Hi, the application which I'm working on is based on a client server architecture |java gui| <- gsoap -> |c++ server| where the server is a windows or unix program, which embeds the business logic. I want to make a gui for users, who don't need to know about that and simply start the gui as if it was the whole app. Thus the gui is managing server instantiation - gui started && server not running => gui starts server. gui started && server running => gui uses server. server has no more session within timeout => server exits gracefully. So what I actually would need is a singleton server and this would mean to query the OS for the existence of the server process. Java has no method to query process lists on a system independent level or to check, whether there is a certain process running - there's just rudimentary support for process control. Java is gui standard here. So I made a little app (nmmutex) which is supposed to control a named mutex for the server's main thread. This app exits always and writes it's result (acquired, not acquired) to the return code. The mutex is queried in a non-blocking manner (try_to_lock). Java can run that process via Runtime.exec. Using that mutex, the server itself may control, whether there is already an instance running. It also can try_to_lock the mutex, and if it's not available, may return. The server itself could also take the role of nmmutex, i.e. to query the mutex. The caveat of using the mutex is, as far as I understood, that boost interprocess objects like mutex and shared memory due to portability have 'kernel or filesystem' persistence. On windows it's filesystem persistence. So if the server crashes, it might not be restartable even after a reboot. And the user can't tell why. I tend to dislike the mutex idea meanwhile, although using it seemed logical to me first: I wanted to restrict use of server's main block to a single thread. I could try to get a soap session at gui startup and assume the server does not run when it fails. Or maybe there's a library which hides querys to the os, like process list, behind a portable interface. Cheers Werner
modified on Thursday, January 27, 2011 4:00 AM