Search code examples
javavariablescallcloudsim

get a value from a method main Class A to another method Class B


I declared the variable public static in the first class A so, I can access it from Class B but, the variable can be only calculated in the main method of Class A and it's calculable I get the value in the same class but in the class B I get a zero :

public class A {
public static double CloudMakespan;


 public static double  CalculCloudMakespan(){
                          
                         double cloudms = 0;
   
                         int A= SimulationSetup.getCloudlet().length-1;
                         
  double executionEndTimeLastCloudlet = SimulationSetup.getCloudlet([A].getFinishTime();
        
  double executionStartTimeFisrtCloudlet=SimulationSetup.getCloudlet()[0].getExecStartTime();
                         
                          cloudms= executionEndTimeLastCloudlet - executionStartTimeFisrtCloudlet;
                       
                          return cloudms; }


`public static void main(String[] args){



Cloudsim.startSimulation();
Cloudsim.EndSimulation();
CloudMakespan=CalculCloudMakespan();


}

i tried to do this in Class B

Class B{
private double totalMakespan;
private tasksMakespan;

public double doSomeCalCul(){

totalMakespan=ClassA.CloudMakespan+taskMakespan;


}



}

the problem is the method DoSomeCalcul() is called before the calcul of the variable Cloudmakespan

and I can't call it after that because starting the simulation is the result of specified instructions one of them is calculating the Cloud Makespanyour text


Solution

  • Maybe you can loop multiple times in "DoSomeCalcul" until variable Cloudmakespan is ready. Of course, It is low efficiency in this way. It is better to call back "DoSomeCalcul" when Cloudmakespan is ready.