📄 deliverthread.java
字号:
package com.ut.smgp.api.thread;
import com.ut.smgp.api.structure.*;
import com.ut.smgp.api.logic.*;
import com.ut.smgp.api.configure.*;
import com.ut.smgp.api.*;
import java.net.*;
import java.util.*;
public class deliverThread extends Thread{
private int cycle=0;
private socketStruct socket=null;
private socketLogic send=new socketLogic();
private initStruct init=new initStruct();
private int ctl=0;
private deliverVector deliverQueue;
private String deliverLock;
private activeTestThread active;
// private Thread deliv=null;
private int timeout=0;
private double startTime=0;
/* public void setDeliv(Thread deliv)
{
this.deliv=deliv;
}*/
/************************************************************
*
* 设置接收线程的睡眠时间
*
*/
public void setTimeOut(int timeout)
{
this.timeout=timeout;
startTime=System.currentTimeMillis();
}
/*************************************************************************
* cycle unit: second
*
*/
public deliverThread(activeTestThread active,initStruct init,deliverVector deliverQueue,String deliverLock)
{
this.cycle=init.getReceiveCycle()*1000;
//this.socket=socket;
this.init=init;
this.deliverQueue=deliverQueue;
this.deliverLock=deliverLock;
this.active=active;
}
public void setCtl(int ctl)
{
this.ctl=ctl;
}
public void run()
{
for (; ; )
{//循环接收数据
if (ctl == 1)
break;
startTime=System.currentTimeMillis();
synchronized (deliverLock)
{//锁定接收标志用于控制用户的接收进程。
for (; ; ) {
if(active.getConnection().socket==null)
{
deliverLock=configure.ERROR_CONNECT_FAILED+"";
if(ctl==3) break; //用户唤醒的,不允许再度睡眠,以避免死锁
try{
Thread.sleep(36000);//睡眠,等待用户接收程序唤醒
}catch(InterruptedException e){}
}
if (ctl == 1)
break;
//接收信息
int total = send.cycleReceive(active.getConnection(), deliverQueue);
if (total!= 0 )
break; //接收队列中有数据则释放接收队列的控制权,唤醒用户的接收程序
if(timeout!=0)
{
int delayTime = (int) (System.currentTimeMillis() - startTime);
if(delayTime>timeout)
{
//timeout=0;
break; //超时则释放接收队列的控制权,唤醒用户的接收程序
}
if(delayTime>1000000000) startTime=System.currentTimeMillis();
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -