The way to live your life.....java style
/**
* Life, as we know it.
* @author - you'd have to figure that out.
*/
public class Life implements Runnable {
private static Life instance = null;
private boolean alive = true;
/** Constructor made private to ensure you only get one life to live */
private Life() {
}
/**
* Singleton used to give you an instance of life
* @return an instance of life
*/
public static Life getInstance() {
if (instance == null) instance = new Life();
return instance;
}
/**
* Called to live the life given to you.
* @throws OutOfMoneyException when that wallet just runs of of green
* @throws FailedLoveLifeException happens often, plenty of fish in the sea
* @throws LoseParentsException It will happen
* @throws AccidentException thrown constantly by the live method
* @throws UnemploymentException happens in life infrequently, just handle
* it right away to avoid a
* OutOfMoneyException
* @throws AddictionException too many nights at the bar can cause this.
*/
public void live() throws
OutOfMoneyException,
FailedLoveLifeException,
LoseParentsException,
AccidentException,
UnemploymentException,
AddictionException {
//Put your own code here
}
public void run() {
while (alive) {
try {
live();
} catch (OutOfMoneyException e) {
continue;
} catch (FailedLoveLifeException e) {
continue;
} catch (LoseParentsException e) {
continue;
} catch (AccidentException e) {
continue;
} catch (UnemploymentException e) {
continue;
} catch (AddictionException e) {
continue;
} catch (ThreadDeath e) {
alive = false;
}
}
}
public class OutOfMoneyException extends Exception {}
public class LoseParentsException extends Exception {}
public class FailedLoveLifeException extends Exception {}
public class AccidentException extends Exception {}
public class UnemploymentException extends Exception {}
public class AddictionException extends Exception {}
public static void main(String args[]) {
Life life = Life.getInstance();
Thread t = new Thread(life);
t.start();
t.join();
life == null;
System.gc();
}
}
credit to: Daniel Hinojosa
0 Comments:
Post a Comment
<< Home