Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Pseudo Remote Threads works

Status
Not open for further replies.

mbuallen

Programmer
Jun 3, 2003
2
0
0
DE
Hallo,
this is a program i intend to run in Java,but i get some errors.Can someone please help me to correct it.Thanks
Programcode:

//The class Sqrt calculates the sum of roots
//between the values dblStart and dblEnd.
//The calculation is done within the jobCode() method
//It implements the JobCodeInt interface and implementation
//code is within the jobCode() method
//use the constructor to pass data to the class and to
//initialize resources that are local to the Job
//Dispatcher machine. In this example, the range of numbers
//for which the sum of square roots is to be calculated is
//sent to the class
import java.lang.Thread;
import java.math.*;
public class Sqrt implements JobCodeInt
{

double dblStart, dblEnd, dblPartialSum;

public Sqrt(double Start,double End)
{
dblStart = Start;
dblEnd = End;
}

public Object jobCode()
{
dblPartialSum = 0;
for(double i=dblStart;i<=dblEnd;i++)
//can make calls to standard Java functions and objects.
dblPartialSum += Math.sqrt(i);

//return the result an object of a standard Java class.
return (new Double(dblPartialSum));
}
}

//this class can have any name of your choosing
//the name JobDispatcher has been chosen merely for convenience

public class JobDispatcher
{
public static void main(String args[])
{
double fin = 10000000; //represents 10 raised to 9
double finByTen = fin/10; //represents 10 raised to 8
long nlStartTime = System.currentTimeMillis();
//range is from 1 to 3*10^8
Sqrt sqrt1 = new Sqrt(1,finByTen*3);
//range is from ((3*10^8)+1) to 10^9
Sqrt sqrt2 = new Sqrt((finByTen*3)+1,fin);

//The following creates two instances of PseudoRemThr class.
//The parameters to this constructor are as follows.
//First parameter: An instance of a class representing a subtask
//Second parameter: Remote Host on which this subtask
//will be executed
//Third parameter: A descriptive name for this
//PseudoRemThr instance.
PseudoRemThr psr1 = new
PseudoRemThr(sqrt1,&quot;//192.168.0.1:3333/&quot;,&quot;Win98&quot;);
PseudoRemThr psr2 = new
PseudoRemThr(sqrt2,&quot;//192.168.0.1:3333/&quot;,&quot;Win2K&quot;);

psr1.waitForResult(); //wait for execution to get over
psr2.waitForResult();

//get the result from each thread
Double res1 = (Double)psr1.getResult();
Double res2 = (Double)psr2.getResult();
double finalRes = res1.doubleValue() + res2.doubleValue();

long nlEndTime = System.currentTimeMillis();
System.out.println(&quot;Total time taken: &quot; + (nlEndTime-nlStartTime));
System.out.println(&quot;Sum: &quot; + finalRes);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top