Results 1 to 5 of 5
- 04-01-2011, 07:49 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 3
- Rep Power
- 0
way from executing thread to JApplet
Hi folks,
when an applet running in two instance (eg. in two tab in firefox) in the same browser then static variables are shared between the two instance, so statics cannot be used for implementing global variables.
It seems to be a good idea to maintain only one public static Map-like object that holds one set of globals for every applet instance as values, and the key may be an object that somewhat refers to the applet instance - this object need to be derived from the thread that actually runs the applet's methods. Unfortunately i found that the same threads and threadgroups are operating on all the applet instances in one browser (jvm).
Is there any way to get any information from a thread that identifies the applet instance (JApplet object?) itself where the thread is operating actually?
- 04-05-2011, 04:39 AM #2
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
This may be true, but it isn't guaranteed.when an applet running in two instance (eg. in two tab in firefox) in the same browser then static variables are shared between the two instance
This would be the Event Dispatch Thread I believe, and from my understanding there should only be the one.this object need to be derived from the thread that actually runs the applet's methods. Unfortunately i found that the same threads and threadgroups are operating on all the applet instances in one browser (jvm).
It occurs to me that using a static mapping is a quite complicated manner of implementing instance variables. Where is this information needed? Is there a separate thread from which you are accessing these variables? Could you not acquire a reference to the JApplet, and then use getter and setter methods to manipulate these values?
- 04-05-2011, 08:53 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 3
- Rep Power
- 0
Everywhere. There are some class instances (globals) grouped in one 'holder' class. Since now the holder had public static members to provide access to these globals from all of the app's methods through HolderClass.globalMember form. But finally i realized that static members are shared (or may be shared) between applet instances, therefore i'm looking for a way to change statics to instances. But without rewriting hundreds of methods to pass holder instance in.Where is this information needed?
Yes there are more threads, but i think it does not matter in this case because if there was only one EDT i would still need to get the reference to the holder shomehow in the deeps of method calls.Is there a separate thread from which you are accessing these variables?
Yes, i'm looking for a way to do this exactly... :) without passing at least one reference through many-many method calls.Could you not acquire a reference to the JApplet
In other words: there is a method running on a specific thread operating on a specific object instance - and this method needs to determine the JApplet instance where the object ('this' in the method) "lives in" without getting it as a parameter.
- 04-05-2011, 02:00 PM #4
Member
- Join Date
- May 2010
- Posts
- 26
- Rep Power
- 0
Well you've kind of stumped me as I'm unsure of an elegant way to solve your problem. From the sound of it I would suggest refactoring your code but you said:
Depending on what is actually done by this chain of method calls, I'm thinking that you could create a new class which extends Thread, say MyThread, which contains the reference you desire. Then, the first method call of any given sequence could be called thusly:But without rewriting hundreds of methods to pass holder instance in.
-Edit- A call to join may be necessary if you wish to wait on the completion of these methodsJava Code:new MyThread(JAppletReference, new Runnable() { public void run() { firstMethodCall(); } }).start();
Then on down the chain, all your methods will be executing on this thread. Retrieve the reference simply:
I'm not sure if it is the best way, but it is the first thing I thought of.Java Code:((MyThread) Thread.currentThread()).getJAppletReference();
Last edited by JavaRulez; 04-05-2011 at 02:05 PM.
- 04-05-2011, 02:36 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
JApplet on MAC
By ld_pvl in forum Java AppletsReplies: 0Last Post: 08-23-2009, 01:40 PM -
JFrame to JApplet or JApplet to JApplet
By ramesh.8189 in forum AWT / SwingReplies: 13Last Post: 02-08-2009, 06:14 AM -
How to stop thread from being jumping off the code without executing it.....
By chiragkini in forum Threads and SynchronizationReplies: 6Last Post: 01-22-2009, 03:38 AM -
JApplet Problem
By tanmoy.b81 in forum AWT / SwingReplies: 2Last Post: 07-28-2008, 06:56 AM -
help with converting to JApplet
By Simmy in forum AWT / SwingReplies: 2Last Post: 08-09-2007, 08:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks