Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Ensuring single instance of app?
|
Posted: Aug 8, 2003 12:22 PM
|
|
> Up front here I want to admit that I am a newbie Java > programmer and make no claims to being an expert. > > That said, couldn't this be solved by making it a > singleton?
Nope. A singleton would be single-instance in on each JVM, not on the machine (or the OS, as it were).
Usually, when you launch an app, a whole new JVM process is created to host it. (If you are on Windows, look at the Task Manager after running more than one java app and you'll see that there are several instances of java, on Linux/Unix/OS X look at ps).
This is the problem that Frank is thinking about when he suggests a blog on the topic. It is also what I was implying with the container comment above. If you could sort of integrate the JVM into the OS, so that the OS would pass requests to run class files off to the already-running JVM, instead of launching a new JVM, then that would solve the problem.
Frank, on the resolution thing, you can also provide the button to launch "control desk.cpl", which adds a little convenience and simplicity for the users. Even better than that, you can launch straight to the "Settings" tab, which has the resolution settings, by executing "rundll32 shell32.dll,Control_RunDLL desk.cpl,@0,4".
(I've not tried this from Java with Runtime.exec(). I don't remember whether it is necessary to fully-qualify the target program name. If so, replace rundll32 with "c:\\windows\\system32\\rundll32.exe"; of course, you should get the Windows system directory from the OS (API call), or at least use the windir environment variable and then add the "\\system32" part to it.)
|
|