I’m on Twitter now
Monday, May 12, 2008 — Abel MuiñoI finally gave up on trying to resist. Curiosity was stronger… so now you can read my tweets at http://twitter.com/amuino
I finally gave up on trying to resist. Curiosity was stronger… so now you can read my tweets at http://twitter.com/amuino
If you have not yet read it, lets go and check the piece of code causing a deadlock.
In order to not spoling the fun, I’m providing the answer in the full post.
Suppose you have this class:
public class Singleton implements Runnable {
public static final String A_STRING = "Hello World".toLowerCase();
public static final Singleton INSTANCE = new Singleton();
public static Singleton getInstance() {
return INSTANCE;
}
private Singleton() {
super();
launchThread();
}
public void launchThread() {
synchronized (this) {
Thread t = new Thread(this);
t.start();
while (t.isAlive()) {
try {
wait(100);
} catch (InterruptedException e) {
// Interrupted.
}
}
}
}
public void run() {
System.out.println(A_STRING);
}
public static void main(String[] args) {
Singleton.getInstance();
}
}
If you run the main method, it hangs in a deadlock. Can you see the reason?
I’ve come across this interesting classification of developer types, by Frank Kelly.
It is a funny read… just try to assign a label to your workmates… and think which label they’ll apply to you :-).
I’m just back from my easter break and catching up with all q4e-related mail and issues… there has been lots of work and contributions, which means a lot of work for us (the committers) but also means a healthy community.
Thanks to everyone who’s been hacking at Q for Eclipse this weekend and in the past.
You rock!