Jump to content
2 posts in this topic

Recommended Posts

last week, I download new Jas intel amd 10.4.8 patched Dvd image, and installed it on my pc without any problem. However, today when I run my java code which is using mlutiple-threads, the system crashed immediately.

 

this is my pc:

 

Pentium D 3.0G;

mainboad 82865G;

Memory 1G.

 

please help me, I want to stick with osx to develop my project.

 

many thanks.

Here is the code, (I abstract the code to this, its a visitor pattern)

 

public void testThread() throws TCException, InitializedException {

 

ThreadA a = new ThreadA();

a.start();

a.addTask(new TaskMock());

a.addTask(new TaskMock());

a.addTask(new TaskMock());

while(a.isHealthy());

}

public class ThreadA extends Thread{

 

private boolean run;

private List list;

public ThreadA() {

run = true;

list = new LinkedList();

}

 

public void addTask(Ta task){

synchronized(list){

this.list.add(task);

}

}

 

 

public boolean isHealthy(){return run || this.list.size() > 0;}

 

public void run() {

while(this.isHealthy()){

if(this.list.size() > 0){

Ta t = null;

synchronized(list){

t = (Ta)list.remove(0);

}

t.process();

 

}

 

}

}

public void terminal(){

run = false;

}

}

public interface Ta {public void process();}

 

public class TaskMock implements Ta{

public void process() {

System.out.println("task has been processed");

}

}

 

 

 

======

while(a.isHealthy());

here is a memory leak,

should be

a.terminal();

while(a.isHealthy());

but this should not crash the system.

Edited by puddlor
×
×
  • Create New...