Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

thread dont start

Posted on 2001-06-14
4
Medium Priority
?
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 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