How can I write singleton to work through several processes? Is it possible?
For example I have code that works with Remote Service in Android. How can I write singleton for this purpose?
How can I write singleton to work through several processes? Is it possible? For
Share
This one is singleton that is simply written, lazy and thread safe. You can use
MySingleton.SOLEdirectly or put it to other variables, but they all will be only references to one only instance. You can use it in as many processes as you wish, it shall weather them all. (processes in Android are threads really)It is not my idea, it is from Effective Java, Second Edition
As for global data using (put that requirement into the question, please), you could reach
MySingleton.SOLEfrom everywhere. Static constants are global. Of course, names would be yours.Of course any thing has its workaround. You can fool this singleton by classloading.
If you really want to have one instance for several different tasks, not threads, then the easy solution will be singleton build as Hybernate or other ORM object. All processes will see the same row in the same table with the same data. But I think it is the overkill for your task.