[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

thread dont start

Posted on 2001-06-14
4
Medium Priority
?
161 Views
Last Modified: 2010-03-31
i am runing a c++ program, calling java program through jni wrap.
the java program start 2 thread (totaly 3 java threads).
i insert print before the java thread start and in the run method, and i dont get the print in the run method.
e.g:

main thread:
a.start();
a.isAlive(); -> this one print true!!

and in a thread:
run()
{
System.out.println("start a"); -> this print i dont get
}

i run the same program on unix enviroment and it work o.k.
on nt enviroment using jre 1.3 and jre 1.1.7 - dont work.

there are several senarios in nt, that the small program do work, but i could not find the difrent when it work and not.
the senario that i have that this small program dont work, are those that the java thread are called before the start of the main c++ method. (they are called in the constractor of a global c++ object), but i have several other senarios like the above, that are called before the main c++ process start, that do work.
0
Comment
Question by:talih
  • 2
4 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 6191355
Do you extend thread, or implement runnable?

If you implement runnable, make sure you create your thread like:

a = new Thread( this ) ;

if you are extending thread, and overriding run() then it seems weird...can you post some code?

Good Luck,

Tim.
0
 

Expert Comment

by:mattdunlap
ID: 6192632
class Test implements Runnable
{
Test()
{
Thread t = new Thread(this);
t.start();
}
run()
{
System.out.println("test");
}
  public static void main(String arg[])
  {
    Test myTest = new Test();
  }
}

This should work?
but then again I learned Jave from my dog.
0
 
LVL 35

Accepted Solution

by:
TimYates earned 800 total points
ID: 6194335
Try:

class Test implements Runnable
{
private Thread t = null ;
public Test()
{
}

public void start()
{
  if( t == null )
  {
    t = new Thread(this);
    t.start();
  }
}

public void run()
{
  System.out.println( "test" ) ;
}

public void stop()
{
  t = null ;
}

public static void main(String arg[])
{
  Test myTest = new Test();
}

}


Tim.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9033790
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to TimYates]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question