通过Socket实现进程间异步通讯(一)
2004-09-08 17:03
549 查看
第一步写一个线程类 CommThread.java
package com.hode.thread;
/**
* @author 泰伯子仪
*/
public abstract class CommThread extends Thread
{
private boolean shouldRun = false;
private int sleepTime = 2000;
private boolean isWait = false;
private boolean isWork = true;
/**
*
*/
public CommThread()
{
//super("CommThread");
Thread commThread = new Thread(CommThread.this);
shouldRun = true;
}
public CommThread(int sleepTime)
{
//super("CommThread");
Thread commThread = new Thread(CommThread.this);
shouldRun = true;
this.sleepTime = sleepTime;
}
public void threadStart()
{
start();
}
public void run()
{
while (shouldRun)
{
try
{
sleep(sleepTime);
}
catch (InterruptedException e)
{
System.err.println("线程Thread1意外终止。");
}
if (!getWait())
{
isWork = true;
System.out.println("/n处理开始");
dispose();
isWork = false;
System.out.println("/n处理完毕");
}
else
{
isWork = false;
System.out.println("等待中.../n");
}
}
}
public void shutdown()
{
shouldRun = false;
}
public void setWait(boolean bool)
{
isWait = bool;
}
public boolean getWait()
{
return isWait;
}
public boolean getWork()
{
return isWork;
}
public abstract void dispose();
}
该类为虚类,其中需函数public abstract void dispose()是线程中需要处理的程序部分
package com.hode.thread;
/**
* @author 泰伯子仪
*/
public abstract class CommThread extends Thread
{
private boolean shouldRun = false;
private int sleepTime = 2000;
private boolean isWait = false;
private boolean isWork = true;
/**
*
*/
public CommThread()
{
//super("CommThread");
Thread commThread = new Thread(CommThread.this);
shouldRun = true;
}
public CommThread(int sleepTime)
{
//super("CommThread");
Thread commThread = new Thread(CommThread.this);
shouldRun = true;
this.sleepTime = sleepTime;
}
public void threadStart()
{
start();
}
public void run()
{
while (shouldRun)
{
try
{
sleep(sleepTime);
}
catch (InterruptedException e)
{
System.err.println("线程Thread1意外终止。");
}
if (!getWait())
{
isWork = true;
System.out.println("/n处理开始");
dispose();
isWork = false;
System.out.println("/n处理完毕");
}
else
{
isWork = false;
System.out.println("等待中.../n");
}
}
}
public void shutdown()
{
shouldRun = false;
}
public void setWait(boolean bool)
{
isWait = bool;
}
public boolean getWait()
{
return isWait;
}
public boolean getWork()
{
return isWork;
}
public abstract void dispose();
}
该类为虚类,其中需函数public abstract void dispose()是线程中需要处理的程序部分
相关文章推荐
- 通过Socket实现进程间异步通讯(二)
- 通过Socket实现进程间异步通讯(三)
- 通过Socket实现进程间异步通讯(四)
- 通过Socket实现进程间异步通讯(二)
- 通过Socket实现进程间异步通讯(三)
- 通过Socket实现进程间异步通讯(四)
- 通过Socket实现进程间异步通讯(一)
- 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法
- [转]在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(一)
- 【转】 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架2
- 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(一)----基础类库部分
- 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法
- 在 AIX 上通过数据管道实现进程间通讯
- [转]在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)
- Android应用中通过AIDL机制实现进程间的通讯实例
- SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论 SignalR 简单示例 通过三个DEMO学会SignalR的三种实现方式 SignalR推送框架两个项目永久连接通讯使用 SignalR 集线器简单实例2 用SignalR创建实时永久长连接异步网络应用程序
- Android应用中通过AIDL机制实现进程间的通讯实例
- 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)
- 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法
- [转载]在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法