Solved

thread dont start

Posted on 2001-06-14
4
152 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 200 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now