📄 threadtest.java
字号:
package sample;/** * @File: ThreadTest.java * @Description: Thread Test for CMPP2.0, MT sent or/and MO received thread test * @Copyright: Copyright 2002 By AsiaInfo(c) ISMG. All right reserved * @Date: 2002-10-24 * @Version 1.0 */import java.io.*;import aiismg.jcmppapi30.CMPPAPI;/** * @Description: A class for reading parameter from console, creating MT or/and * MO thread, and testing the java api of cmppapi2.0 */public class ThreadTest{ /** * created threads counts */ private static int ciThreadCount = 0 ; /** * loop times of each thread */ private static int ciThreadLoop = 0 ; /** * time out seconds at receiving MO */ private static int ciTimeOut = 0; /** * boolean flag of creating sending MT thread */ private static boolean cbSendThread = false ; /** * boolean flag of creating receiving MO thread */ private static boolean cbRecvThread = false ; /** * boolean flag of writing parameter and msg file at receiving MO */ private static boolean cbWriteFile = false ; /** * parameter file name of sending MT */ private static String csArgFile = null ; /** * @Description: print help message about this tool * @Return: none */ private static void cvPrintUsage () { System.out.println ( "" ) ; System.out.println ( "AsiaInfo ISMG thread Test tool for CMPP2.0. Version 1.0" ); System.out.println ( "" ) ; System.out.println ( "ThreadTest <-c digit> <-l digit> <-s | -r> [-f argfile] [-t timeout] [-w] [-v]" ) ; System.out.println ( " Usage -c : created thread counts, int value " ) ; System.out.println ( " -l : each thread loop, int value" ) ; System.out.println ( " -s : run send MT thread" ) ; System.out.println ( " -r : run recv MO thread" ) ; System.out.println ( " -f : arg file when send MT" ) ; System.out.println ( " -t : time out second, int value, default is no time out" ) ; System.out.println ( " -w : write parameter and msg file at receiving MO"); System.out.println ( " -v : Show this screen" ) ; System.out.println ( "" ) ; } /** * @Description: return the loop time of each thread, specified by user input * @Return: int value, equal or larger than zero */ public static int ciGetThreadLoop ( ) { return ciThreadLoop ; } /** * @Description: return the argument file name at sending MT,specified by user input * @Return: String value, should not be null */ public static String csGetArgFile() { return csArgFile ; } /** * @Description: return time out value at receiving MO, specified by user input * @Return: int value, equal or larger than zero, and zero means waits forever */ public static int ciGetTimeout() { return ciTimeOut ; } /** * @Description: return the flag of writing parameter and msg file when receiving MO * @Return: boolean value, true means write output file, default is false */ public static boolean cbGetWriteFile() { return cbWriteFile ; } /** * @Description: main function */ public static void main(String arg[]) { if ( arg.length <= 0 ) { cvPrintUsage () ; System.exit ( 1 ) ; } //parse input argument int liErrRet = 0 ; for ( int i=0; i<arg.length; i++ ) { if ( arg[i].compareTo ("-c") == 0 ) { i++ ; if ( i >= arg.length ) { liErrRet = -1 ; break ; } else { try { if ( (ciThreadCount = Integer.parseInt (arg[i])) <= 0 ) { liErrRet = -1 ; break ; } } catch ( NumberFormatException e ) { System.out.println ( "Error: Illegal thread count value = " + arg[i] ) ; liErrRet = -1 ; break ; } } } else if ( arg[i].compareTo ("-l") == 0 ) { i++ ; if ( i >= arg.length ) { liErrRet = -1 ; break ; } else { try { if ( (ciThreadLoop = Integer.parseInt (arg[i])) <= 0 ) { liErrRet = -1 ; break ; } } catch ( NumberFormatException e ) { System.out.println ( "Error: Illegal thread loop value = " + arg[i] ) ; liErrRet = -1 ; break ; } } } else if ( arg[i].compareTo ("-s") == 0 ) { cbSendThread = true ; } else if ( arg[i].compareTo ("-r") == 0 ) { cbRecvThread = true ; } else if ( arg[i].compareTo ("-t") == 0 ) { i++ ; if ( i >= arg.length ) { liErrRet = -1 ; break ; } else { try { if ( (ciTimeOut = Integer.parseInt (arg[i])) < 0 ) { liErrRet = -1 ; break ; } } catch ( NumberFormatException e ) { System.out.println ( "Error: Illegal time out value = " + arg[i] ) ; liErrRet = -1 ; break ; } } } else if ( arg[i].compareTo ("-f") == 0 ) { i++ ; if ( i >= arg.length ) { liErrRet = -1 ; break ; } else { csArgFile = arg[i] ; } } else if ( arg[i].compareTo ("-w") == 0 ) { cbWriteFile = true ; } else if ( arg[i].compareTo ("-v") == 0 ) { cvPrintUsage() ; System.exit ( 1 ) ; } else { liErrRet = -1 ; break ; } } //end for if ( liErrRet != 0 ) { cvPrintUsage() ; System.exit ( 1 ) ; } //start MT sending if ( cbSendThread == true ) { //threads for send MT ThreadSend[] coSendRunner = new ThreadSend[ciThreadCount]; Thread[] coSendThread = new Thread[ciThreadCount]; int i; CMPPAPI loSendCMPPAPI = new CMPPAPI() ; loSendCMPPAPI.InitCMPPAPI("../config/javacmppc.ini"); System.out.println("Start MT Sending..."); for (i=0;i<ciThreadCount;i++) { coSendRunner[i] = new ThreadSend(); coSendThread[i] = new Thread(coSendRunner[i]); coSendThread[i].start(); } try { for (i=0;i<ciThreadCount;i++) { coSendThread[i].join(); } System.out.println("End MT Sending..."); } catch (InterruptedException e) { System.out.println(e.toString()); } System.out.println("Success:" + Integer.toString(Counter.ciSendSuccess)); System.out.println("Fail: " + Integer.toString(Counter.ciSendFail)); } //end cbSendThread == true //start MO receiving if ( cbRecvThread == true ) { ThreadRecv[] coRecvRunner = new ThreadRecv[ciThreadCount]; Thread[] coRecvThread = new Thread[ciThreadCount]; int i; CMPPAPI loRecvCMPPAPI = new CMPPAPI() ; loRecvCMPPAPI.InitCMPPAPI("../config/javacmppc.ini"); System.out.println("Start MO receiving..."); for (i=0;i<ciThreadCount;i++) { coRecvRunner[i] = new ThreadRecv(); coRecvThread[i] = new Thread(coRecvRunner[i]); coRecvThread[i].start(); } try { for (i=0;i<ciThreadCount;i++) { coRecvThread[i].join(); } System.out.println("End MO receiving..."); } catch (InterruptedException e) { System.out.println(e.toString()); } System.out.println("Success:" + Integer.toString(Counter.ciRecvSuccess)); System.out.println("Fail: " + Integer.toString(Counter.ciRecvFail)); } //end cbRecvThread == true } //end main ( String arg[] )}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -