From owner-freebsd-java Fri May 17 13:12:57 2002 Delivered-To: freebsd-java@freebsd.org Received: from smg.is.titech.ac.jp (smg.is.titech.ac.jp [131.112.35.1]) by hub.freebsd.org (Postfix) with ESMTP id 8BC9337B404 for ; Fri, 17 May 2002 13:12:48 -0700 (PDT) Received: from tripper.private (smg [131.112.35.1]) by smg.is.titech.ac.jp (Postfix) with ESMTP id 4ED4C2B0E6; Sat, 18 May 2002 05:12:47 +0900 (JST) Date: Sat, 18 May 2002 05:12:29 +0900 Message-ID: <55661mfs9e.wl@dittohead.is.titech.ac.jp> From: Fuyuhiko Maruyama To: "Amir Bukhari" Cc: freebsd-java@freebsd.org Subject: Re: AW: RMI and Thread with jdk1.3.1 In-Reply-To: <000001c1fdc0$250be810$3b00a8c0@C39> References: <200205170841.34641.ernsth@nl.euro.net> <000001c1fdc0$250be810$3b00a8c0@C39> User-Agent: Wanderlust/2.9.9 (Unchained Melody) on XEmacs/21.5.5 (beets) MIME-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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 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