⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsend.java

📁 亚信java实例 移动短信接口 cmpp3.0
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package sample;import aiismg.jcmppapi30.CMPPAPI;import aiismg.jcmppapi30.CMPPDeliverResp;import java.io.*;import java.net.*;import java.util.Date; import java.util.*; public class TestSend {	public static void main( String argv[] ) throws IOException	{   	long dd = 12;   	int bc = 0;   	String input;   	LogToFile logToFile = new LogToFile("TestSend");		Queue myQueue = new Queue();		CMPPAPI herepCMPPAPI=new CMPPAPI();		if( herepCMPPAPI.InitCMPPAPI( "../config/javacmppc.ini" ) != 0 ) 		{			//System.out.println( "Fail to call InitCMPPAPI!" );			//System.exit( 1 );			logToFile.DoLog("Fail to call InitCMPPAPI!");		}		else		{			logToFile.DoLog("Success to call InitCMPPAPI!");		}		System.out.println("我准备向队列里面写入东西");		/*		myQueue.enq("QA");		myQueue.enq("QB");		myQueue.enq("QC");		myQueue.enq("QD");		myQueue.enq("QE");		myQueue.enq("QF");		myQueue.enq("QG");		myQueue.enq("QGG");		myQueue.enq("QH");		myQueue.enq("QI");		myQueue.enq("QJ");		myQueue.enq("QK");		myQueue.enq("QL");		myQueue.enq("QM");		myQueue.enq("QN");		myQueue.enq("QO");		myQueue.enq("QP");		myQueue.enq("QQ");		myQueue.enq("QR");		*/			while (bc<500)		{			myQueue.enq("QA");			myQueue.enq("QB");			myQueue.enq("QC");			myQueue.enq("QD");			myQueue.enq("QE");			myQueue.enq("QF");			myQueue.enq("QG");			myQueue.enq("QGG");			myQueue.enq("QH");			myQueue.enq("QI");			myQueue.enq("QJ");			myQueue.enq("QK");			myQueue.enq("QL");			myQueue.enq("QM");			myQueue.enq("QN");			myQueue.enq("QO");			myQueue.enq("QP");			myQueue.enq("QQ");			myQueue.enq("QR");			myQueue.enq("QS");			myQueue.enq("QT");			myQueue.enq("QU");			myQueue.enq("QV");			myQueue.enq("end");			bc++;		}		System.out.println("主进程队列处理完毕,队列长度是"+myQueue.GetLength());		DaemonThread daemonSendThreadA = new DaemonThread(myQueue);		daemonSendThreadA.setDaemon(true);		daemonSendThreadA.start();		System.out.println("主进程队列处理完毕等待守护进程工作");		try		{			daemonSendThreadA.join();		}		catch ( InterruptedException ex)		{		}		/*		while(daemonSendThreadA.isAlive() && bc<1500000)	  {			if ( bc % 1000 == 0)	   		System.out.println("主进程等待守护进程中,第"+bc+"次");				bc = bc+1;	   	for (int aaa=0;aaa<20000;aaa++)	  	{	   		dd = 25*25*bc;	   	}	  }		*/	  System.out.println("主进程等待守护进程结束,它"+daemonSendThreadA.isAlive()+"活着");		  System.exit(0);	}//end of main  //LogToFile logToFile = new LogToFile("TestReceive");}//end of class TestReceive/*here is the Queue Class code*/class Queue {	static Vector hereVector;	static int hereLength;	public Queue() 	{ 		if (hereVector==null)		{			hereVector= new Vector();			hereLength = 0;		}	}	public static  synchronized void enq(Object x) { 		//super.addElement(x); 		hereVector.add(x);		hereLength++;	} 		public static synchronized Object deq() { 		/* 队列若为空,引发EmptyQueueException异常 */ 		if( empty() ) 			{return null;}		Object x = hereVector.elementAt(0); 		hereVector.removeElementAt(0); 		hereLength--;		return x; 	} 		public static  synchronized Object front() { 		if( empty() ) 			{return null;}		return hereVector.elementAt(0); 	} 	public static  boolean empty() { 		return hereVector.isEmpty(); 	} 	public static  synchronized void clear() { 		hereVector.removeAllElements(); 	} 		public static  int search(Object x) { 		return hereVector.indexOf(x); 	}	public static  synchronized int GetLength() { 		return hereLength;	} } class LogToFile{	String logStr = new String();	PrintWriter log;	String logFile = new String();	String extFile = new String();	int countNum=0;	final int WarningNum=200000;	int a=1;		public LogToFile(String inLogFile){		GregorianCalendar lpMyCalender = new GregorianCalendar( );		logFile = "./"+inLogFile+lpMyCalender.get(lpMyCalender.YEAR)+(1 + lpMyCalender.get(lpMyCalender.MONTH))+lpMyCalender.get(lpMyCalender.DATE);		//logFile = "./"+inLogFile+(1900+new Date().getYear())+"-"+(1+new Date().getMonth())+"-"+new Date().getDate();		extFile = ".log";		try { 			log = new PrintWriter(new FileWriter(logFile+extFile, true), true); 		} 		catch (IOException e) { 			System.err.println("无法打开日志文件: " + logFile); 		} 	}		public synchronized void DoLog(String inStr)	{		log.println(new Date() + " % " + inStr.replace('\n','N').replace('\r','R') + " %end% "); 		countNum++;		if (countNum>WarningNum)		{			try 			{ 				log = new PrintWriter(new FileWriter(logFile+"_"+a+extFile, true), true); 				countNum=0;				a++;			} 			catch (IOException e) 			{ 				System.err.println("无法打开日志文件: " + logFile); 			}		}	}}/*here is the monitor resource control code*/class ResControlCenter{	static int readyNum=0;	static int runningNum=0;	static int AllNum=0;	static int DeadNum=0;	static int CouldRunning=4;//初始设置。默认4,最大99	static int MaxNum=9;//促使设置。默认9,最大99	String[] nameAry;	int[] status;		public ResControlCenter(int inMaxNum,int inCouldRunNum)	{		if (inMaxNum>1)		{			MaxNum = inMaxNum;		}		if (inCouldRunNum>1)		{			CouldRunning =	inCouldRunNum;		}		nameAry = new String[(MaxNum+1)];		status = new int[(MaxNum+1)];		for (int t=0;t<MaxNum;t++)		{			nameAry[t]="X-0"+t+"C";			status[t]=0;		}	}	synchronized public void AddReadyNum(int i){		status[i] = 1;//写成READY状态		readyNum = readyNum+1;		AllNum = AllNum+1;	}	synchronized public void AddRunningNum(int i){		status[i] = 2;//写成Running状态		runningNum = runningNum+1;		readyNum = readyNum-1;	}	synchronized public void SubRunningNum(int i){		status[i] = 1;//写成READY状态		runningNum = runningNum-1;		readyNum = readyNum+1;		notifyAll();	}	synchronized public void AddDeadOne(int i){		status[i] = 0;//写成Dead状态		runningNum = runningNum-1;		readyNum = readyNum-1;		AllNum = AllNum-1;		DeadNum = DeadNum+1;		notifyAll();	}	synchronized public void AddCouldRunNum(int i){		if (CouldRunning+i<=MaxNum)		{			CouldRunning = CouldRunning+i;		}	}	synchronized public void SubCouldRunNum(int i){		if (CouldRunning-i>1)		{			CouldRunning = CouldRunning-i;		}	}	synchronized public int GetAllNum(){		return AllNum;	}	synchronized public int GetReadyNum(){		return readyNum;	}	synchronized public int GetRunningNum(){		return runningNum;	}	synchronized public int GetMaxNum(){		return MaxNum;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -