posts - 24,  comments - 25,  trackbacks - 0

DataThread.java控制其他线程是否运行:

public class DataThread extends Thread
{
    
public void run()
    
{
        SendThread send 
= null;
        Thread SendThread 
= new Thread(send);
        
while (true)
        
{
            
try
            
{
                
if ("0158".equals(WmsFormatter.toParamTime(new Date()).substring(04)))
                
{
                    
if (SendThread.isAlive())
                    
{
                        send.close();
                    }

                }


                
if (!hostSendThread.isAlive())
                    
{
                        send 
= new SendThread();
                        SendThread 
= new Thread(send);
                        SendThread.start();
                    }

                Thread.sleep(
50000);
            }
catch (Exception e)
            
{
             
try {
                    e.printStackTrace();
                        
continue;
                   }
 catch (Exception e1) {
                         
continue;
                   }

            }

        }

    }


    
public static void main(String[] args)
    
{
        
new DataThread().start();
    }


SendThread.java
public class SendThread implements Runnable
{
    
private boolean flag = true;

    
public void close()
    
{
        flag 
= false;
    }


    
public void run()
    
{
        
while (flag == true)
        
{
            
        }

    }

}
posted on 2011-04-19 11:13 Jarry 阅读(163) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: