?
Solved

thread dont start

Posted on 2001-06-14
4
Medium Priority
?
158 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

771 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