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

📄 jremotethread.java

📁 JAMPACK Grid programming
💻 JAVA
字号:
/**
 *
 * Program         : JRemoteThread.java
 *
 * Author          : Vijayakrishnan Menon
 *
 * Date            : 13th Dec 2005
 *
 * Organization    : Centre for Excellence in 
 *						Computational Engineering and Networking (CEN),
 *                   		Amrita Viswa Vidyapeetham
 **/

package JAMPack;

/** The design is intended to have a distributed thread class. The class is also
  * an RMI server and can be remotely controlled by the remote referance handle.
  * The namming service will bind an instance of this remote thread 
  * ("JRemoteThread"). The client gets a referance to the "RemoteThread" and can
  * manage a thread that actually runs on a remote machine, through rmi calls. 
  * The RemoteThread object can be reused and can persist unless forcefully
  * removed. 
  **/

public class JRemoteThread extends java.rmi.server.UnicastRemoteObject
  implements RemoteThread, Runnable  {

    private int _rank;
    private int _size;
    private int _remoteThreadID;
    private boolean _isSuspended = false;
    private Thread _remoteThread;
    private Task _task;
    private boolean _valid = false;
    private JGrid _workGrid;

    public  JRemoteThread(int ID) throws java.rmi.RemoteException{
        this._remoteThreadID = ID;
    }

    public JRemoteThread(int rank, int size, Task task, JGrid grid) throws java.rmi.RemoteException{
        this._rank = rank;
        this._size = size;
        this._task = task;
        this._remoteThread = new Thread((Runnable)this);
        this._valid = true;
        this._workGrid = grid;
    }


    /** The Runnable method that runs in a seperate remote thread. This executes
      * the user task */
    public void run() {
    	this._task.setGrid(this._workGrid);
    	this._task.runTask(_rank,_size);//,_workGrid);
        this._valid = false;
    }


    /***************************************************************************
     * The following Methods belong to the RemoteThread
     ***************************************************************************/

    /** Remote method to initialise and reset the remote thread */
    public void initialise(int rank, int size, Task task, JGrid workGrid) throws java.rmi.RemoteException {
		if(!this._valid)
        {
            this._rank = rank;
            this._size = size;
            this._task = task;
            this._remoteThread = new Thread((Runnable)this);
            this._valid = true;
            this._workGrid = workGrid;        
    	}	    
    }

    /** Remote method to stop the remote thread */
    public void stop() throws java.rmi.RemoteException {
        this._remoteThread.stop();
        this._valid = false;
    }

    /** Remote method to start a fresh remote thread. unlike the convectional
      * start method this can be reused provide the remote thread is valid */
    public void start() throws java.rmi.RemoteException {
        if(this._valid)
            this._remoteThread.start();
    }

    /** Remote method to get the name of the remote thread */
    public String getName() throws java.rmi.RemoteException {
        return this._remoteThread.getName();
    }

    /** Remote method set priority to the remote thread. The priority is with
      * respect to the remote machine's scheduler and JVM   
      **/
    public void setPriority(int newPriority) throws java.rmi.RemoteException {
        this._remoteThread.setPriority(newPriority);
    }

    /** Remote method to suspend the remote thread */
    public void suspend() throws java.rmi.RemoteException {
        if(_isSuspended) return;
        else
        {
            this._remoteThread.suspend();
            this._isSuspended = true;
        }
    }

    /** Remote method to resume suspended remote threads */
    public void resume() throws java.rmi.RemoteException {
        if(_isSuspended)
        {
            this._remoteThread.resume();
            this._isSuspended = false;
        }
        else return;
    }

    /** Remote method to check the life of the remote thread */
    public boolean isAlive() throws java.rmi.RemoteException {
        return this._remoteThread.isAlive();
    }
    
    /** Returns the thread ID of the remote thread */
    public int getID() throws java.rmi.RemoteException {
    	return this._remoteThreadID;
    }
    
    /** Returns the validity of this thread */
    public boolean getValidity() throws java.rmi.RemoteException {
    	return this._valid;
    }
    
    public void setGrid(JGrid grid) throws java.rmi.RemoteException {
    	this._workGrid = grid;
    	this._task.setGrid(grid);
    }
}

⌨️ 快捷键说明

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