img
. .
number of outstanding requests per client. These are the methods
incrementOutstandingRequests(), decrementOutstandingRequests(), and
waitForOutstandingRequests(). When the client sends the "End" message, we will not
close the socket until the number of outstanding requests has dropped to zero.
Making a Native Call to pthread_setconcurrency()
Here we simply show the basic interface for making a native call to set the concurrency level to 10.
Code Example 17-4 uses the Solaris UI threads function thr_setconcurrency(), which will
run on all post-Solaris 2.1 systems [pthread_setconcurrency() is part of UNIX98 and not
implemented until Solaris 7].
Example 17-4 Setting the Concurrency Level in Solaris (TimeDiskSetConc.java)
/* NativeThreads.c
*/
#include <thread.h>
#include <unistd.h>
#include <jni.h>
JNIEXPORT void JNICALL Java_Test_NativeTSetconc(JNIEnv *env, jclass
obj) {
thr_setconcurrency(10);
}
/*
Test.java */
public class Test {
static native void NativeTSetconc();
static {System.loadLibrary("NativeThreads");
public static void main(String argv[]) {
...
NativeTSetconc();
...
}
}
Actual Implementation of POSIX Synchronization
In Code Example 17-5 we have the actual implementations of explicit POSIX-style mutexes and
condition variables. Take note of how InterruptedException is handled.
Example 17-5 Correct Implementation of Mutexes and Condition Variables
// Extensions/Mutex.java
/*
Pthreads style mutexes.
Not recursive.
*/
package Extensions;
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home