From: Godmar Back (gback@cs.utah.edu)
Date: Thu Dec 17 1998 - 16:49:45 EST
The awt toolkit deadlocks for Les Schaffer on his P/90.
The program for which that happens is FileViewer.java (appended)
and it's likely somewhere in the pack call.
The two threads that deadlock are the main thread and the awt event queue
thread, as one would expect.
The two locks in question are the lock on
java.awt.Toolkit.class object and a lock on an
instance of java.awt.Toolkit.
So, for instance, the following code could cause this:
java.awt.Toolkit() {
synchronized static a() {
Toolkit t;
t.f();
}
synchronized f() {
a();
}
}
Does that ring a bell?
- Godmar
--- FileViewer.java ---
// from Java in a Nutshell 1ed.
import java.awt.*;
import java.io.*;
public class FileViewer extends Frame {
Button close;
public FileViewer(String filename) throws IOException{
super("FileViewer: " + filename);
File f = new File(filename);
int size = (int) f.length();
int bytes_read = 0;
FileInputStream in = new FileInputStream(f);
byte [] data = new byte[size];
while( bytes_read < size)
bytes_read += in.read(data, bytes_read, size-bytes_read);
TextArea textarea = new TextArea(new String(data, 0), 24, 80);
textarea.setFont(new Font("Helvetica", Font.PLAIN, 12));
textarea.setEditable(false);
this.add("Center", textarea);
close = new Button("Close");
System.out.println("Frame opened ...");
this.add("South", close);
System.out.println("Packing viewer");
this.pack();
System.out.println("Displaying viewer");
this.show();
}
public boolean action(Event e, Object what) {
if( e.target == close ) {
this.hide();
this.dispose();
return true;
}
return false;
}
static public void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Usage: java FileViewer <filename>");
System.exit(0);
} else {
System.out.println("Starting FileViewer: " + args[0]);
}
try {
System.out.println("Opening Frame");
Frame f = new FileViewer(args[0]);
}
catch (IOException e) {
System.out.println(e);
}
}
}
This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 19:57:21 EDT