puddlor Posted January 16, 2007 Share Posted January 16, 2007 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. Link to comment https://www.insanelymac.com/forum/topic/38857-java-thread-crashs-new-jas-osx1048/ Share on other sites More sharing options...
puddlor Posted January 16, 2007 Author Share Posted January 16, 2007 (edited) 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 January 16, 2007 by puddlor Link to comment https://www.insanelymac.com/forum/topic/38857-java-thread-crashs-new-jas-osx1048/#findComment-277004 Share on other sites More sharing options...
Recommended Posts