Code on pthreads and Java Multihtreading