Php exec not waiting for complete java function

Dear All,
I have java function as below. If you notice this class calls another class that is SMSClient and in that class I have other classes called too. So then I write a php as below and is just call this function and return the results. I want to wait for all the class to function and only finally return the answer. How make it wait for the entire function to complete? Thank you.

$output = array();
$return_var = 0;
exec("java callSMSClient +60164562233 test1", $output, $return_var);
$output_str = join($output, "\

echo "<pre>The output was:\
echo "The return value was $return_var</pre>";
public class callSMSClient{

  public static void main(String[] args)
  	SMSClient t1 = new SMSClient(1);
  	if (args.length > 0)
  	 String phoneNumber= args[0];
  	 String messageSend = "";
  	 System.out.println("ARgs lenght is :"+args.length);
  	 for(int i=1;i<args.length;i++)
  	 	  messageSend = args[i];
  	 	  messageSend = messageSend+" "+args[i];	
  	 //System.out.println("Message sent  :"+messageSend);