After viewing the film "Inception," I was inspired to use the new try
-with-resources statement to summarize the film:
public static void main(String... args) {
try(CloseableDreamLevel dl1 =
kickOnClose(createCityScape(firstClassCabin)) ) {
try(CloseableDreamLevel dl2 =
kickOnClose(createHotel(dl1))) {
try(CloseableDreamLevel dl3 =
kickOnClose(createSnowMountainFortress(dl2))) {
inception();
try(CloseableDreamLevel dl4 =
kickOnClose(enterLimbo(dl3))) {
findTheLost();
}
}
}
}
}
private static DreamLevel enterLimbo(DreamLevel dl) {
return
new DreamLevel() {
void kick() {
try {
if ((new java.util.Random()).nextBoolean())
Thread.currentThread().sleep(Integer.MAX_VALUE);
} catch (InterruptedException ie) {}
}
};
}
:-)
Please help stop spreading bad programming habits.
The problem with the code above is the empty catch block of InterruptedException,
that is, not re-asserting the interuption.
Taken directly from http://java.sun.com/j2se/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html:
(see "How do I stop a thread that waits for long periods (e.g., for input)?")
<<... any method that catches
an interrupt exception and is not prepared to deal with it immediately
reasserts the exception. We say reasserts rather than rethrows, because it is not always possible to rethrow the exception.
If the method that catches the InterruptedException is not
declared to throw this (checked) exception, then it should "reinterrupt
itself" with the following incantation:
Thread.currentThread().interrupt();
This ensures that the Thread will reraise the InterruptedException as soon as it is able.>>
a very BROAD overview but clever nonetheless
:)
and to Kostis Anagnostopoulos...do you really think this post was meant to be technical at all??
maybe you need some sleep...or a vacation because you take things TOO seriously
@Kostis Anagnostopoulos stop spreading.
very nice \^_\^