The Artima Developer Community
Sponsored Link

Java Answers Forum
Accessing the function of a thread/runnable

1 reply on 1 page. Most recent reply: Apr 13, 2005 4:36 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Shaitan

Posts: 11
Nickname: shaitan00
Registered: Feb, 2005

Accessing the function of a thread/runnable Posted: Apr 13, 2005 3:12 AM
Reply to this message Reply
Advertisement
Coding Style: NetBeans IDE 4.0 Beta2 (Java)

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.


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Accessing the function of a thread/runnable Posted: Apr 13, 2005 4:36 AM
Reply to this message Reply
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.

Flat View: This topic has 1 reply on 1 page
Topic: a problem about compareTo(Object rv) Previous Topic   Next Topic Topic: Convert Excel Applications to Java or .Net

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use