Writing by shivdev on Wednesday, 27 of April , 2011 at 9:31 pm
Folks, look no further. java.util.UUID works great. I’ve tried the Axis’s UUIDGenFactory and and was NOT unique. 10 reps of 40 threads pounding simultaneously. At least, two or three of the forty were duplicates every time (only thirty seven were unique) Geeze!!! And I thought it was the synchronization.
java.util.UUID.randomUUID().toString(); // This works
Moreover, it uses SecureRandom number generator algorithms – so it is secure (in terms of predicting the next UUID etc.).
Category: Java
Writing by shivdev on Wednesday, 20 of April , 2011 at 9:30 pm
As a developer I’m constantly restarting processes. For instance, if I have 2 Java Process (Server/Web) and an Eclipse Java Process which makes 3 Java Processes. The problem is to kill only the server and web processes and leave the eclipse java process intact.
Solution 1 (The Hard and Manual approach):
Find the java processes and kill them manually
ps -ef | grep java
kill -9 1
kill -9 2
Solution 2 (The Simplified Approach – killjava):
Create an alias or run the following:
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/”|xargs kill -9
This will kill all java processes – which means you will need to restart eclipse each time you run this.
Solution 3 (The Tuned Approach – killweb):
Create an alias or run the following based on a keyword (say, Web process remote_debug port 4096):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | grep 4096 | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9
Create an alias or run the following based on a keyword (say, Server process remote_debug port 2048):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | grep 2048 | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9
This will kill only the specific processes you want to terminate.
Solution 4 (The BEST Way – Combine 1 and 2 in a single alias – killdebug):
Create an alias or run the following (Use egrep to look for multiple keywords above):
ps -A|grep java|sed -e “s/\s*\([0-9]*\).*/\1/” | xargs ps -p | egrep “2048|4096” | sed -e “s/\s*\([0-9]*\).*/\1/” | xargs kill -9
This will kill all processes you WISH to terminate.
I have aliases for Solutions 2, 3 and 4 depending on what I’m trying to do. So there you go – hope that helps!
Category: Linux,Tips and Tricks