When should I create a checked exception, and when should I make a runtime exception?
For example, suppose I created the following class:
public class Account {
private float balance;
/* ... constructor, getter, and other fields and methods */
public void transferTo(Account other, float amount) {
if (amount > balance)
throw new NotEnoughBalanceException();...
I am using the CountDownLatch to synchronize an initialization process between two threads and i was wondering about the proper handling of the InterruptedException that it might throw.
the code i initially wrote was this:
private CountDownLatch initWaitHandle = new CountDownLatch(1);
/**
* This method will block until the thread has fully initialized, this should only be called ...
Iam little bit confused about the use of yield() method in java in the following example .one of the concept with yiled() is 'used to prevent execution of thread'.
My problems are
1.With and with out using yield method in the bellow code the same output is obtained.is it correct?
2.Actually what is the main use of yiled()
3.How it is different from join() and interrupt() methods
publi...
Is there any possibility of exceptions to occur other than RuntimeException in Java? Thanks.
I have a thread:
Thread t = new Thread(){
public void run(){
ServerSocketConnection scn = (ServerSocketConnection)
Connector.open("socket://:1234");
// Wait for a connection.
SocketConnection sc = (SocketConnection) scn.acceptAndOpen();
//do other operation
}
};
t.start();
Lets say no client is connecting to the Server, so this thread wi...
The Java documentation is not clear on this point. What happens if you call interrupt on a Thread before it calls Thread.sleep():
//interrupt reaches Thread here
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
return;
}
Will the InterruptedException be thrown?
Edit: If you know the answer can you please point me to relevan...
I'm developing simple survey service. I collect statistics in backend instance and dump them into datastore every hour. I registered shutdown hook for my backend instance so that data collected within last hour is not lost. I also use cache to store some of my data.
Strangely call to MemcacheService.get() in LifecycleManager.ShutdownHook.shutdown() causes InterruptedException to be thrown. Her...
I want to implement something like this.
1.A background process which will be running forever
2.The background process will check the database for any requests in pending state. If any found,will assign a separate thread to process the request.So one thread per request.Max threads at any point of time should be 10. Once the thread has finished execution,the status of the request will be updat...
How can I make a thread run only if the other thread is running too, meaning, if I return from run in one thread, then I want the other to stop running too,
my code looks something like this:
ClientMessageHandler clientMessagehandler = new ClientMessageHandler();
ServerMessageHandler serverMessagehandler = new ServerMessageHandler();
Thread thread1 = new Thread(serverMessagehandler);
...