Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 May 2002 05:12:29 +0900
From:      Fuyuhiko Maruyama <fuyuhik8@is.titech.ac.jp>
To:        "Amir Bukhari" <bukhari@fzi.de>
Cc:        freebsd-java@freebsd.org
Subject:   Re: AW: RMI and Thread with jdk1.3.1
Message-ID:  <55661mfs9e.wl@dittohead.is.titech.ac.jp>
In-Reply-To: <000001c1fdc0$250be810$3b00a8c0@C39>
References:  <200205170841.34641.ernsth@nl.euro.net> <000001c1fdc0$250be810$3b00a8c0@C39>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
Hi,

On Fri, 17 May 2002 18:30:23 +0200, Amir Bukhari wrote:
> 
> I use freebsd 4.5 StABLE.
> 
> this the java version I use linux-jdk1.3.1 :
> java version "1.3.1_02"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
> Classic VM (build 1.3.1_02-b02, green threads, nojit).
> 
> Note : I have also tried the port jdk1.3.1p5
> 
> Sorry but I cant put the source code, because it very big ( more than
> 3000 lines), but I can put
> the main class, which provide RMI. I have build it with javac
> 
> I know that java is independet plattform, therefor my programm should
> work also under freebsd,
>  that mean there something wrong with my installation or I have missing
> to install something, there is a
> configuration I must do before using java,
>  but I have installed java from the port collection, which install also
> dependeries.

> 
> My main Program (Server) do the following:
> 1- run RMI Regestry at port 1099
> 2- then wait for a connection from the client, which a specified
> command.
> 3- when it received command from the client it then start the simulation
> Program, which should be run as Thread.
> 
> Clien Site:
> the client only send the command to the server.
> 
> Source code :
> import java.rmi.*;
> import java.rmi.server.*;
> import java.rmi.registry.*;
> import java.util.*;
> import java.net.*;
> 
> class RMISimServerImpl extends UnicastRemoteObject
>         implements RMISimServerInterface
> {
>   int STOP = 1, START = 2 , PAUSE = 3, QUIT = 4, CONTINUE = 5;
>   RMISimProtokol protokol = new RMISimProtokol();
>   EventSimPar arg = new EventSimPar();
>   String modell;
>   int cmd = -1;
> 
>   public RMISimServerImpl() throws RemoteException {}
> 
>   public RMISimServerImpl(String filename, EventSimPar argument) throws
> RemoteException {
>     modell = filename;
>     arg = argument;
>   }
> 
>   public void SendCommand(int command) throws RemoteException
>   {
>     cmd = command;
> 
>     System.out.println("Command was Send"); // as Tes, but this was not
> displayed when i have sended a command !!
>   }
> 
>   public void SendEvent(RMIEvent rmievent) throws RemoteException
>   {
>     protokol.SetEvent(rmievent);
>   }
>   public void prozessCommand() {
>     int command = -1;
>     //System.out.println("Waiting for command");
>     while(command == -1) {
> 
>       if (cmd == START) {
>         protokol.SetCommand(cmd);
>         EventSim evtSim = new EventSim(modell, arg); // this is The
> Simulation Programm which run as Thread
>         evtSim.start();
>         cmd = -1;
>       } else if (cmd == QUIT) {
>        protokol.SetCommand(cmd);
>        command = 0;
>       } else if (cmd == STOP) {
>         protokol.SetCommand(cmd);
>       }else if (cmd == PAUSE) {
>         protokol.SetCommand(cmd);
>       }else if (cmd == CONTINUE) {
>         protokol.SetCommand(cmd);
>       }

I think your program is stacking in this loop.  This program seems
to expect other thread will have a thread of control during the thread
executing prozessCommand() is looping.  However Java doesn't
guarantee that and our current JDK uses green_threads that doesn't
perform preemption so that your EventSim thread have a thread of
control.  If you place a Thread.yield() here, your program will
start simulation.

This kind of polling loop shouldn't be written without special reason
for any programs including non-Java program.  It only eats CPU but
produces nothing.

> 
>     }
>     System.exit(0);
>   }

--
Fuyuhiko MARUYAMA <fuyuhik8@is.titech.ac.jp>
Matsuoka laboratory,
Department of Mathematical and Computing Sciences,
Graduate School of Information Science and Engineering,
Tokyo Institute of Technology.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?55661mfs9e.wl>