开发者

How to implement a single instance app manager in java (CVM PhoneME)?

I'm working on a application manager for embeded platform based on the CVM PhoneME VM. The VM is started by a C++ app which configures the CVM and then triggers the VM itself. This C++ app is called form the command line passing the main class name and the classpath of a java application. There is a main java app (lets call it Manager) which loads the app using classloaders. I want th开发者_开发问答is manager to be a single instance application so it could track all running apps.

In other words: The first time I start an app (app1 for instance), the VM will launch and the Manager will load the app1. In further calls to load other apps (app2, app3 and so on), the same instance of the Manager would load those apps.

The manager is working fine, except for the fact that this is not a single instance.

Is it possible to do what I want?

I found this: http://www.knowledgesutra.com/forums/topic/59760-how-to-implement-single-instance-application-on-java/

This is almost the same I want, except for the app loading part. However, the necessary packages are not available in the CVM implementation.


There are various ways to enforce a single instance of an application. Firefox uses a lock file, for example.

One of the most common ways I've seen is to launch the "manager" regardless, but at launch, try to open a ServerSocket on some port listening for connections.

If you fail to open the socket, you know you're not the singleton instance. So, instead of launching the app, connect to the listening socket and send it the program arguments instead.

If you succeed in opening the socket, do what was asked to launch app1 while on another thread listen for incoming connections from those managers launched as duplicate instances.

Edit: This describes the process in a non-ME environment. Not being an ME developer, I can't comment on its feasibility on a phone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜