codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Multithreading question  ericwi at 10:51 on Monday, December 18, 2006
 

Hi all,

I am new to this topic and would like to consult any experts on this. I have a code where it shows

"

......
new Thread ( new Runnable()
{
public void run()
{
// boring coding }
} ).start();

........

// further down the code I have

....

Thread test = new Thread();
test.start();



public void run()
{
//runs test code
}
........

"


When it comes to the portion where class test is instianted, the function run() does not seem to run. Does anyone has thoughts on this?


Thanks

  Re: Multithreading question  mmarab at 14:22 on Monday, December 18, 2006
 

Does your class have:

class CLASS_NAME implements Runnable {

}

Give that a try!

  Re: Multithreading question  crwood at 22:09 on Monday, December 18, 2006
 


Thread test = new Thread();
test.start();

The test Thread has no Runnable to run so it does nothing. In your first thread you had an inner class Runnable. To get this test Thread to run you can do as mmarab suggests

class Pseudo implements Runnable
{
...
Thread test = new Thread(this);
test.start();
...
/** Runnable (single method) implementation */
public void run()
{
//runs test code
}
}

or you can do

class Pseudo
{
...
Thread test = new Thread(runner);
test.start();
...
private Runnable runner = new Runnable()
{
public void run()
{
//runs test code
}
};
}

If there is no Runnable then there will not be a run method to run.

  Re: Multithreading question  ericwi at 00:04 on Tuesday, December 19, 2006
 

Hi all,

Thanks for the reply. I will give a try.


Merry Xmas y'll.

  Re: Multithreading question  ericwi at 08:37 on Tuesday, December 19, 2006
 

Hi all,

I've found a little tweak. It works when I add 'this' to Thread xxx = new Thread(this).

  Re: Multithreading question  mmarab at 08:43 on Tuesday, December 19, 2006
 

Yes the use of 'this' would refer to the object in which you wanted the thread for. so in your case the class.

Nice One.

Merry Xmas.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007