Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exchange value between a thread and a class

Status
Not open for further replies.

ushtabalakh

Programmer
Jun 4, 2007
132
I have a variable in a thread class that is being constantly modified

How can I access that variable from another class every x seconds?
 
I wish I could send variables by refrence to the thread class but apparently Java has no such capabilities.

My second solution was to use a timer object, but apparently a timer can be used as a separate class itself, so the next problem becomes how to exchange value between our class and the timer
 
I don't like that sollution. You should be careful with that, as you may have synchronization problems.

I'd declare a method in the thread class that would return the variable in a safe way.

Cheers,
Dian
 
do you wanto to access the variable for reading or for writing?
 
Then, a not synchronized access may cause non consistent behaviour ...

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top