Solved

thread dont start

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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

734 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