From owner-freebsd-java@FreeBSD.ORG Thu Jun 3 13:45:22 2004 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 883E516A4CE for ; Thu, 3 Jun 2004 13:45:22 -0700 (PDT) Received: from smtp13.wxs.nl (smtp13.wxs.nl [195.121.6.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4C8DA43D1D for ; Thu, 3 Jun 2004 13:45:22 -0700 (PDT) (envelope-from ronald-freebsd7@klop.yi.org) Received: from ronald.echteman.nl (ip51cdc5d2.adsl-surfen.hetnet.nl [81.205.197.210]) by smtp13.wxs.nl (iPlanet Messaging Server 5.2 HotFix 1.25 (built Mar 3 2004)) with SMTP id <0HYR005JN2ZL9W@smtp13.wxs.nl> for java@freebsd.org; Thu, 03 Jun 2004 22:45:21 +0200 (CEST) Received: (qmail 10398 invoked from network); Thu, 03 Jun 2004 20:45:20 +0000 Received: from unknown (HELO laptop.thuis.klop.ws) (192.168.1.4) by ronald.echteman.nl with SMTP; Thu, 03 Jun 2004 20:45:20 +0000 Received: (qmail 5204 invoked from network); Thu, 03 Jun 2004 20:45:20 +0000 Received: from unknown (HELO guido.thuis.klop.ws) (192.168.0.2) by 192.168.0.16 with SMTP; Thu, 03 Jun 2004 20:45:20 +0000 Received: (qmail 10645 invoked from network); Thu, 03 Jun 2004 20:45:19 +0000 Received: from localhost.thuis.klop.ws (HELO outgoing.local) (127.0.0.1) by localhost.thuis.klop.ws with SMTP; Thu, 03 Jun 2004 20:45:19 +0000 Date: Thu, 03 Jun 2004 22:45:18 +0200 From: Ronald Klop In-reply-to: <20040603120810.096a1975@psych.iad.vt.edu> To: Daniel Fisher , java@freebsd.org Message-id: MIME-version: 1.0 Content-type: text/plain; format=flowed; delsp=yes; charset=iso-8859-1 Content-transfer-encoding: 7BIT User-Agent: Opera M2/7.50 (FreeBSD, build 673) References: <20040601154601.0869f5b4@psych.iad.vt.edu> <40BD7C06.5050205@noc.ntua.gr> <20040602095245.48cb3c44@psych.iad.vt.edu> <20040603120810.096a1975@psych.iad.vt.edu> Subject: Re: possible threading problem X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2004 20:45:22 -0000 On Thu, 3 Jun 2004 12:08:10 -0400, Daniel Fisher wrote: > On Wed, 02 Jun 2004 21:42:59 +0200 > Ronald Klop wrote: > >> On Wed, 2 Jun 2004 09:52:45 -0400, Daniel Fisher >> wrote: >> >> > On Wed, 02 Jun 2004 10:04:38 +0300 >> > Panagiotis Astithas wrote: >> > >> >> Daniel Fisher wrote: >> >> > I'm experiencing a weird threading problem with jdk-1.4.2p6_3 that >> I >> >> don't >> >> > see on Linux. >> >> > It looks like the BSD JDK is not honoring sychronize statements. >> >> > Has anyone seen this before? >> >> > If not, who should I send sample code to? >> >> >> >> Um, the list? >> >> -- >> >> Panagiotis Astithas >> > >> > Alrighty then.... >> > attached is a tarball with the sample classes in it. >> > Untar and cd into the directory. >> > Execute: java -jar prop.jar >> > These classes monitor the main.properties file and echo the changes to >> > stdout. >> > Edit main.properties while the java job is running. >> > FreeBSD JVM throws an InterruptedIOException, Linux JVM does not >> throw an >> > exception. >> >> Add debugging like, so you can make sure synchronized is (not) working. >> synchronized (a) { >> System.out.println("In a 1"); >> ... >> System.out.println("Out a 1"); >> } >> >> If I recompile your program I get other results after modifying the >> properties file. >> java.lang.NoClassDefFoundError: prop/PropEvent >> at prop.PropSingleton.removeProperties(PropSingleton.java:74) >> at prop.PropMonitor.run(PropMonitor.java:71) >> at java.lang.Thread.run(Thread.java:534) >> >> PropMonitor interrupts itself. Why? it's useless. >> By the way if you don't do this your program works. >> >> Offtopic: >> In PropMonitor you catch Exception. So you will mis all other possible >> error messages from java. >> If this is not just a test class I would rewrite it. >> Why this: >> try { >> throw Exception(); >> } catch (Exception) { >> break; >> } >> >> You can also just do break in stead of the exception. >> And you can remove all the interrupt/interrupted calls. Only keep the >> boolean run. >> And even nicer than the break is setting run = false to end the while. >> >> But only removing the stopMonitor call from PropMonitor.run() will also >> make it work. :-) >> >> Ronald. >> > > I think you've missed the point. > The question is, why does the BSD JVM behave differently and does it need > fixing? Possibly. But you mention a synchronization problem. And I gave an hint about how to modify your program to show the synchronizations and if the FreeBSD Java ignores it. You are using threads. Threads are non-deterministic, so different os'es can show different things. In your program you ignore exceptions by catching Exception and not printing/logging it. So maybe you just don't see the exception on Linux. The point I tried to make is, that it is not clear from your example that java is doing something wrong. Only that it is doing something different than another JVM on another OS. Running the program on Windows might give even other results. BTW: You interrupt your own thread. The javadoc's say that if the thread is not blocked it will set the interrupted flag. I think that the next time a blocking syscall is done the InterruptedIOException is thrown, because the interrupted flag is set. So the InterruptedIOException can be thrown at a very different moment than that the thread.interrupt() call was done. I'm not sure about this, because I don't know enough about the internals of java, but it can be the reason, that it looks like a synchronization problem. Printing more debug info, can show you this. But beware that the printing of the debug info can interfere with the rest of the program. I hope this helps you in debugging this, Ronald. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/