JDK: 1.2beta4-D
OS: Solaris, NT
Locale: ALL
In Solaris and Windows NT, jdk1.2beta4-D, Thread's method yield() will call
application dead. Following is a program to reproduce this bug.
========================CheckThread.java===================================
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class CheckThread implements ActionListener {
static Button b1;
static Button b2;
boolean PAUSE = false;
LittleThread myThread;
public static void main(String args[]) {
new CheckThread();
}
public CheckThread() {
Frame f = new Frame("Check Thread");
f.setLayout(new BorderLayout());
b1 = new Button("pause ");
b1.addActionListener(this);
b2 = new Button("begin");
b2.addActionListener(this);
f.add(b2, BorderLayout.NORTH);
f.add(b1, BorderLayout.SOUTH);
f.pack();
f.show();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1 && myThread != null) {
if (!PAUSE) {
PAUSE = true;
myThread.pause();
b1.setLabel("resume");
} else {
PAUSE = false;
myThread.resume();
b1.setLabel("pause ");
}
} else {
myThread = new LittleThread();
myThread.start();
b2.setEnabled(false);
}
}
class LittleThread implements Runnable {
Choice choice1;
int itemCount = 0;
boolean PAUSE = false;
Thread driver = null;
public LittleThread() {
Frame f = new Frame("Check Choice");
f.setLayout(new BorderLayout());
choice1 = new Choice();
f.add(choice1, BorderLayout.CENTER);
f.pack();
f.show();
}
public void start() {
if (driver == null) {
driver = new Thread(this, "");
driver.start();
}
}
public void pause() {
PAUSE = true;
}
public void resume() {
PAUSE = false;
}
public void run() {
while (true) {
if (PAUSE) {
driver.yield();
continue;
}
if (choice1 != null && itemCount < 40) {
choice1.add("I am Choice, yes I am : " + itemCount * itemCount);
itemCount ++;
}
if (itemCount >= 20 && choice1 != null && choice1.getItemCount() > 0) {
choice1.removeAll();
itemCount = 0;
}
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
}
}
}
}
================================================================================
java CheckThread
press button "begin" to start a thread
press button "pause" to pause it
application dead
jim.hu@prc 1998-05-04
This bug still exists in 1.2beta4-E. I think it should be
fixed in the next build.
jim.hu@prc 1998-05-13
OS: Solaris, NT
Locale: ALL
In Solaris and Windows NT, jdk1.2beta4-D, Thread's method yield() will call
application dead. Following is a program to reproduce this bug.
========================CheckThread.java===================================
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class CheckThread implements ActionListener {
static Button b1;
static Button b2;
boolean PAUSE = false;
LittleThread myThread;
public static void main(String args[]) {
new CheckThread();
}
public CheckThread() {
Frame f = new Frame("Check Thread");
f.setLayout(new BorderLayout());
b1 = new Button("pause ");
b1.addActionListener(this);
b2 = new Button("begin");
b2.addActionListener(this);
f.add(b2, BorderLayout.NORTH);
f.add(b1, BorderLayout.SOUTH);
f.pack();
f.show();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == b1 && myThread != null) {
if (!PAUSE) {
PAUSE = true;
myThread.pause();
b1.setLabel("resume");
} else {
PAUSE = false;
myThread.resume();
b1.setLabel("pause ");
}
} else {
myThread = new LittleThread();
myThread.start();
b2.setEnabled(false);
}
}
class LittleThread implements Runnable {
Choice choice1;
int itemCount = 0;
boolean PAUSE = false;
Thread driver = null;
public LittleThread() {
Frame f = new Frame("Check Choice");
f.setLayout(new BorderLayout());
choice1 = new Choice();
f.add(choice1, BorderLayout.CENTER);
f.pack();
f.show();
}
public void start() {
if (driver == null) {
driver = new Thread(this, "");
driver.start();
}
}
public void pause() {
PAUSE = true;
}
public void resume() {
PAUSE = false;
}
public void run() {
while (true) {
if (PAUSE) {
driver.yield();
continue;
}
if (choice1 != null && itemCount < 40) {
choice1.add("I am Choice, yes I am : " + itemCount * itemCount);
itemCount ++;
}
if (itemCount >= 20 && choice1 != null && choice1.getItemCount() > 0) {
choice1.removeAll();
itemCount = 0;
}
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
}
}
}
}
================================================================================
java CheckThread
press button "begin" to start a thread
press button "pause" to pause it
application dead
jim.hu@prc 1998-05-04
This bug still exists in 1.2beta4-E. I think it should be
fixed in the next build.
jim.hu@prc 1998-05-13