How to access variables in other threads?

L

Lars Willich

Assume we have a class and inside a second thread.
How do I access variables und their functions...
a) ...in the inner thread from the enclosing thread (in the sample below: aaa)
b) ...in the outer thread from the inner thread (in the sample below:bbb)

The way I coded them below doesn't work


public class testouter {
static Thread InnerThread;
String bbb = new String(" blahblah ");
...
InnerThread = new Thread(new Runnable() {
String aaa = new String(" hello ");
...
public void run() {
.....
bbb.trim();
while(...) { .....}
System.exit(1); } } );
InnerThread.start();

InnerThread.aaa.trim();
... } }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top