EJB and Java Serialization (2) test code

Source: Internet
Author: User

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++;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.