Next, interested friends can directly take my test code to test themselves, please modify such as the number of threads, execution time, serialized data volume size and other parameters. If you want to try to do thread dump, you can open the relevant two comments, it will be more convenient, the code has a corresponding comment for reference.
The test code is as follows:
Package test;
Import Java.io.ByteArrayOutputStream;
Import java.io.IOException;
Import Java.io.ObjectOutputStream;
Import java.io.Serializable;
Import java.util.ArrayList;
public class Test implements Runnable {
notice! Set the three test parameter to what your want
/**
* Thread count to run test
*/
private static final int thread_count = 50;
/**
* Seconds to run test
*/
Private static final Long Test_time_second = 1 * 30;
/**
* During test, we serialize a Data instance with a ArrayList that contains DataItem.
* This are to set how many DataItem in the ArrayList.
*/
Private static final long items_count_in_test_object = 1000;
private static int finishedcount = 0;
private static Boolean needstop = false;
private static Object Needstoplock = new Object ();
private static Object Finishedcountlock = new Object ();
private static Boolean isneedstop () {
Synchronized (Needstoplock) {
return needstop;
}
}
private static void Setneedstop () {
Synchronized (Needstoplock) {
Needstop = true;
}
}
private static void Addfinisedcount () {
Synchronized (Finishedcountlock) {
finishedcount++;
}
}