The Artima Developer Community
Sponsored Link

Java Answers Forum
can we create a local variable for a thread??

2 replies on 1 page. Most recent reply: Oct 3, 2002 6:37 AM by Ewen Lewis

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 2 replies on 1 page
senthil

Posts: 23
Nickname: rickk84
Registered: Aug, 2002

can we create a local variable for a thread?? Posted: Sep 30, 2002 7:20 AM
Reply to this message Reply
Advertisement
can we create a local variable for a thread??
can we create variables to threads??
does any thread contain any vaiables of its own??
Whats a object block??
Do we have any class blocks??


Ewen Lewis

Posts: 3
Nickname: lewis
Registered: Sep, 2002

Re: can we create a local variable for a thread?? Posted: Oct 3, 2002 6:08 AM
Reply to this message Reply
If you create your thread as a class it can have local variables although if you wish to pass any data to these it need to be done in the constructor as the run() function cannot have any arguments.

Maybe I didn't do it correctly but to get around this I have a local version of data which is set in the constructor in the thread and also an updateData() which will return the Local Version before the thread terminates if their is a better way would be nice to know.

Hope it helps
Ewen Lewis

Ewen Lewis

Posts: 3
Nickname: lewis
Registered: Sep, 2002

Re: can we create a local variable for a thread?? Posted: Oct 3, 2002 6:37 AM
Reply to this message Reply
Here is some code you may find useful

In code:

<Class> Data1;
<Class> Data2;

Thread Env= new Execution(Data1,Data2);

Env.start();

Data1 = Env.GetUpdatedData1();



class Execution extends Thread
{
<Class> data1;
<Class> data2;

Execution(<Class> Data1, <Class> Data2)
{
this.data1 = Data1;
this.data2 = Data2;
}

public String GetUpdatedData1()
{
//Returns version of Data1 Class
return Data1;
}

public void run()
{
//Do update to Data

}
}

Flat View: This topic has 2 replies on 1 page
Topic: Getting one char out of a String? Previous Topic   Next Topic Topic: ')' expected at line 22

Sponsored Links



Google
  Web Artima.com   

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