Threads Section Index | Page 8
How do I detect end of stream in a non-blocking manner when reading a stream through URL/URLConnection, if available() reports nothing to read on end of stream?
In the fully general case, you can't (since the client can just keep sending you data). Given that Java doesn't have asynchronous I/O (yet), you need to design your system to take i...more
(...or any other IO method that wraps read(), like BufferedReader.readLine(). Calling thread.interrupt() does nothing.) You can't. That's the way it's supposed to work. One workaround is to use ...more
What should you do such that an RMI server program can accept multiple clients and actually parallelize their execution?
Well first theres nothing you can do explicitly for this. This IS the way it works. Multiple client calls to the same object are NOT queued up but concurrent method invocations on an RMI object ar...more
I am on the Java-Threads mailing list, hosted at University of Kent at Canterbury (firstname.lastname@example.org). This is a fairly quiet list but the quality of advice is typically very good. Broadly, t...more
Is there any way to communicate between two classes within an application using InputStreams and OutputStreams?
The PipedInputStream/PipedReader and PipedOutputStream/PipedWriter streams provide synchronized I/O across threads, from within one class or multiple classes. The following example demonstrates th...more
[Short answer: threads are lightweight, programs (aka processes or tasks) are heavyweight. -Alex] Lightweight and heavyweight processes refer the mechanics of a multi-processing system. In a l...more
Starvation is when the Java runtime (JVM) doesn't allocate time to a thread to execute. This may be due to a poor scheduling algorithm (like green Threads under Solaris, where a for loop from 1 to...more
Thread.sleep() sends the current thread into the "Not Runnable" state for some amount of time. The thread keeps the monitors it has aquired -- i.e. if the thread is currently in a synchr...more
How can I create ThreadGroups in applets running in Netscape 4.7 without generating security exceptions?
Sign your code and enable UniversalThreadGroupAccess. PrivilegeManager.enablePrivilege("UniversalThreadGroupAccess"); For a full list of the targets and what tasks they provide access t...more
Check out http://java.sun.com/products/jdk/1.2/docs/guide/misc/threadPrimitiveDeprecation.html. more
Use thread.setDaemon(true) to tell the JVM to make the thread a daemon thread. According to Webster's, a daemon (variant of demon) is an attendant power or spirit. Daemon threads are typically...more
Why are the methods wait() and notify() defined in the Object class when they are used with Threads?
The wait() and notify() methods are object-specific. The wait() method suspends the current thread of execution, and tells the object to keep track of the suspended thread. The notify() method tel...more
If you create threads in a ThreadGroup object, they may be controlled simultaneously with the member functions of said object.
The keyword synchronized is used to acquire a exclusive monitor lock on an object. It can be used to mark either a method or a block of code. In both cases, it means to acquire a lock for the dur...more
A thread is created by the VM behind the scenes during a call to the start() method. It begins its life inside the run() method of the thread subclass instance whose start() method was called. more