Given a thread/runnable [clientListen] that loops to process messages (while loop). This thread/runnable is spawned from my GUI and is then left to work on its own, one of the things the Thread/Runnable does is check to see if a Conferance has started (if so it sets a public static boolean startConfs == true).
What I need to do is, from the GUI, check to see if each thread has conferences started. So in my Thread/Runnable [clientListen] I made a function as follows:
-- in clientListen thread/runnable -- public boolean isActive() { return startConfs; }
-- in main GUI thread -- cListen = new clientListen(); // This starts the thread/runnable which will immediatly enter a while loop processing information ... do stuff.... if (cListen.isActive) { so something } else { do something else }
So in my MAIN code (the one that spawned the Thread/Runnable) I want to do (at any time) cListen.isActive() to determine if the Thread/Runnable set the boolean. Does this violate any threading laws? Also, the thread itself is looping in a WHILE loop non-stop, can I really do a cListen.isActive() from my GUI while it is looping? How can it do 2 things at once?
Hope I was able to clearly illustrate my problem. Any help would be GREATLY appreciated, thanks.
This works without problems. "RealTime" doesn't exist, anyway.
Because it IS possible to access the Threads methods simultaniously, the synchronized modifier exists to prevent you from doing that. This modifier makes sure that all synchronized methods can only be accessed if none of them is "active".
If you don't use the synchronized modifier, you won't have any problems with what you want to do.