Thread is hanging up

HI all,

I am seeing a strange behaviour, I dont know what the problem is ,

I am new to thread world.

I have written a simple java program.

One thread will be periodically running and calling another thread to perform an action based on some condition.. In the below code, whenever the Inner thread calls start method in perform method, it will hang up at that time, It should come once it triggers the another thread. But in rare cases, the caller thread hangs up,

This is not frequent, once in a while it happens,

Could anybody tell what could be reason for one thread to be in RUNNNING state and hanging at some point in the code (at start method of the another thread). and never come out again.

The code is below,

Thanks,

Sheetal,

In the below, code,

The inner thread goes to method(), and to perform method, and hangs out at start() (Line number 29), Count anybody tell the reason.

1 class Inner extends Thread {

2run() {

3 Thread.sleep(20000);

4 try{

5 if (something)

6 mehod();

7 } catch (Exception e){

8}

9}

10

11method(){

12performAction pa = new performAction();

13pa.perform()';

14}

15

16class performAction {

17

18perform{}{

19

20Thread e = new Thread(){ new Runnuable(){

21public void run() {

22try {

23// Do Some actions,

24} catch(Exceptione ){

25};

26

27 }

28}

29e.start);

30 }

[1551 byte] By [Sheetal_d_2006a] at [2007-11-26 23:38:18]
# 1
First you need to read this tutorial. http://java.sun.com/docs/books/tutorial/essential/concurrency/
bangaarama at 2007-7-11 15:02:32 > top of Java-index,Core,Core APIs...
# 2

You need a loop in your Inner Thread, as the run() code is only called once when the thread is started and not repeatedly.

class Inner extends Thread {

public void run() {

while (true) {

try {

Thread.sleep(20000);

} catch (InterruptedException e) {}

if (condition)

//performAction

}

}

}

You probably also want to set the thread as a Daemon thread.

JasonChoya at 2007-7-11 15:02:32 > top of Java-index,Core,Core APIs...
# 3
Post a small demo code that is generally compilable, runnable and could reproduce your problem. See: http://homepage1.nifty.com/algafield/sscce.html and http://www.yoda.arachsys.com/java/newsgroups.html
hiwaa at 2007-7-11 15:02:32 > top of Java-index,Core,Core APIs...