Page 1 of 1

Problem with Singleton classes

Posted: 29 Jul 2010, 04:43
by Satyarth
We were using 1.6.2 with 1.6.6 patch. Recently we did fresh install of 1.6.6. We now see that multiple objects of our singleton class are created.

Same code works as expected in 1.6.2 with 1.6.6 patch. But we see multiple objects of singleton class in fresh 1.6.6 setup.

It seems somehow code is running on multiple JVMs. Is that possible ?

Lapo please comment.

Posted: 30 Jul 2010, 18:34
by Lapo
It's a simple problem with the javaExtensions/ folder.
I think you simply need to include it in your classpath. It was removed in 1.6.6 because it inhibits the runtime reloading of Java code.

You can get more details here:
http://www.smartfoxserver.com/docs/docP ... ons.htm#9a

Posted: 19 Oct 2010, 05:04
by Fraggle
Hi,

I have the same issue.
To avoid loading from the DB all the time, I want to use a singleton to load all the properties of my game elements.
This singleton must be accessible and persistent across all my extensions (I use an extension for lobby, another one for matchmaking and another one for the actual game).

I understand your solution, I just want to know if it's "bad practice" in any way to disable automatic reloading and, especially, to add the folder to the classpath ?

I can live with automatic reloading in dev (with singletons not shared) but I want to be sure I'm not missing any other "unexpected" behavior.

Anyway, this seems like a huge difference of behavior to me, should be very visible in the doc :)

Thanks,

Sebastien

Posted: 19 Oct 2010, 05:54
by Lapo
I understand your solution, I just want to know if it's "bad practice" in any way to disable automatic reloading and, especially, to add the folder to the classpath ?
No it's not bad practice at all.
Good news is... we have simplified and enhanced classpath and class loading significantly in the new SmartFoxServer 2X, coming out next week ;)

cheers

Posted: 07 Jun 2011, 14:25
by Satyarth
Lapo wrote:It's a simple problem with the javaExtensions/ folder.
I think you simply need to include it in your classpath. It was removed in 1.6.6 because it inhibits the runtime reloading of Java code.

You can get more details here:
http://www.smartfoxserver.com/docs/docP ... ons.htm#9a
So is there a way we can use Singleton classes as well as use Automatic Reloading of extensions ?

Posted: 07 Jun 2011, 16:23
by Lapo
I replied via PM.
Anyways, due to how Class Loading works in Java you cannot have both things, namely a singleton and singleton reloading.

Also it sounds illogical. A singleton is an unique object instance. If I reload it there will be a new object, which contradicts the definition of singleton.