Stumped - Java hangs when using Swing in Slime

123 views
Skip to first unread message

levand

unread,
Dec 19, 2008, 3:18:47 PM12/19/08
to Clojure
I noticed this first with a project I'm working on, and verified that
it is happening as well with the temperature converter demo on the
clojure site.

After I run the file from within Slime, after a few seconds my Swing
gui stops responding, and the Repl as well. Apparently, the whole Java
process is hung.

Running the same file from a basic Clojure Repl started from the
command line works fine, with exactly the same VM settings.

I am running on Windows XP with Java 1.6.0_10.

Anyone have any ideas? I'm pretty confused as to what might be going
on. Some sort of deadlock in the thread pool that isn't allowing the
AWT event thread any cycles? I'm looking at the thread pool in JSwat
and I see a lot of Swank threads, but I can't tell exactly what's
going on.

Many thanks,
-Luke

.Bill Smith

unread,
Dec 19, 2008, 3:54:34 PM12/19/08
to Clojure

Daniel Eklund

unread,
Dec 19, 2008, 4:06:58 PM12/19/08
to Clojure
> Anyone have any ideas? I'm pretty confused as to what might be going
> on. Some sort of deadlock in the thread pool that isn't allowing the
> AWT event thread any cycles? I'm looking at the thread pool in JSwat
> and I see a lot of Swank threads, but I can't tell exactly what's
> going on.

I literally just had this problem today. I was having slime hang on
me with _any_ swing code. So I tried the basic repl and even the most
basic

(. javax.swing.JOptionPane (showMessageDialog nil "Hello World"))

and even this was failing. Spent an hour svn updating, etc.

Finally, I clicked on the system icon tray at the bottom right of XP
and noticed that that the stupid Java download manager wanted me to
update. I let it download whatever patch it wanted and then suddenly
everything worked.

It could be coincidental. But I am telling you just in case.

levand

unread,
Dec 22, 2008, 3:40:46 PM12/22/08
to Clojure
Update:

I was actually able to sporadically replicate this problem using
simply Jeffrey Chu's clojure-mode, without Slime or Swank.

It only occurs on this PC. My home workstation, which is running
Windows Vista and the same version of Java, works without a hitch.

Again, everything works fine when run directly from the system command
line - it's got to be something in clojure-mode or emacs itself.
Unfortunately I don't have nearly the emacs knowledge to be able to
tell what's going on in there.

Any pointers would be greatly appreciated... I'm actually switching to
enclojure for windows development because of this, although I'd much
rather use emacs, now that I'm just getting used to it.

Thanks,
-Luke

Michael Beauregard

unread,
Dec 22, 2008, 3:51:25 PM12/22/08
to clo...@googlegroups.com
This is a long shot, but...

It's been a while since I played with swing in clojure, but I remember
the swing UI would display behind emacs. The result is that the app is
correctly running despite the fact that it is obscured by other
windows while your REPL appears stuck.

Michael

levand

unread,
Dec 23, 2008, 9:28:33 AM12/23/08
to Clojure
Yeah, thanks for the suggestion, but that's not it... I can see the
Swing window, and it is also hung (it doesn't process events from the
OS).

I'm going to do some more in-depth debugging today, doing stack dumps
and such, and see if I can figure out what's locking.

Thanks,
-Luke

On Dec 22, 3:51 pm, "Michael Beauregard" <mich...@insightfulminds.com>
wrote:

levand

unread,
Dec 29, 2008, 10:35:35 AM12/29/08
to Clojure
Haven't solved it yet, but I may have found something useful enough
for someone cleverer than I to make something out of.

When I run clojure directly as inferior-lisp, without slime, the
problem does occur. However, as soon as I enter something in the
inferior lisp buffer, it starts working again.

1. I start up clojure with M-x run-lisp
2. I load my test Swing app (the temperature converter) using (load-
file ...).
3. The Swing frame hangs (doesn't respond to events)
4. I hit "enter" in the inferior lisp buffer
5. The Swing frame starts responding again

My best guess is that something is blocking on the input stream from
the Repl, and preventing events from being processed by the event-
handling thread. As soon as something is entered in the Repl, it
somehow clears this state and starts working again.

Any thoughts on how to fix it?

Thanks,
-Luke

Rowdy Rednose

unread,
Dec 29, 2008, 9:17:04 PM12/29/08
to Clojure
What if you run the Swing code in the Event Dispatch Thread?

In other words, does this:

(. javax.swing.SwingUtilities (invokeAndWait #(.
javax.swing.JOptionPane (showMessageDialog nil "Hello World"))))

or

(. javax.swing.SwingUtilities (invokeLater #(. javax.swing.JOptionPane
(showMessageDialog nil "Hello World"))))

work for you?

levand

unread,
Dec 30, 2008, 10:39:09 AM12/30/08
to Clojure
Wow... that actually fixes it. Still a minor problem, since according
to the Sun website, it is legal to create a Swing object in another
thread as long as long as it is not "realized" yet...

Still, this definitely is a doable workaround. Thanks!

-Luke

Rowdy Rednose

unread,
Dec 30, 2008, 7:26:35 PM12/30/08
to Clojure
Just curious - do both invokeLater and invokeAndWait work? Or only
invokeLater?

Rowdy Rednose

unread,
Dec 30, 2008, 7:41:15 PM12/30/08
to Clojure
Luke,

I believe they don't promote the "as long as it's not yet realized"
rule anymore but rather say "do even creation of Swing objects in the
EDT" now: http://java.sun.com:80/docs/books/tutorial/uiswing/concurrency/initial.html

Cheers
Rowdy

On 31 Dez., 00:39, levand <luke.vanderh...@gmail.com> wrote:

CuppoJava

unread,
Dec 30, 2008, 10:27:31 PM12/30/08
to Clojure
I want to add that it's not confined to just Swing applications.

I have the exact same problem using JME on an Emacs *inferior-lisp*
REPL.

The program hangs, until I enter subsequent commands on the REPL.

The SwingUtilities trick, and updating to the latest Java runtime
doesn't help.

I'm going to try installing latest Slime/Swank to see if that helps at
all.

If anyone's worked out the root cause of this problem, please post it
here.
-Patrick

CuppoJava

unread,
Dec 31, 2008, 1:38:40 AM12/31/08
to Clojure
I would like to add that nope... installing SLIME didn't seem to help.

I'm on Clojure rev. 1160, and the latest SLIME and Swank sources as of
December 30 2008.

srol...@gmail.com

unread,
Dec 31, 2008, 11:41:38 AM12/31/08
to Clojure
I experience a similar issue on windows, but not linux. The first time
I create a JFrame
in the lifetime of a JVM, it hangs and the frame does not appear until
I go to the
inferior lisp buffer and hit the enter key. After I do this once it
behaves normally when
creating subsequent JFrames.

I connected jconsole to see what was going on, and at the point it is
hung the
awt event queue thread is in a native method
sun.awt.windows.WDesktopProperties.init
Not sure what that method is doing or why swank would cause it to
hang. I may
look into it more when I have some time.

Name: AWT-EventQueue-0
State: RUNNABLE
Total blocked: 0 Total waited: 0

Stack trace:
sun.awt.windows.WDesktopProperties.init(Native Method)
sun.awt.windows.WDesktopProperties.<init>(WDesktopProperties.java:58)
sun.awt.windows.WToolkit.initializeDesktopProperties(WToolkit.java:
934)
java.awt.Toolkit.getDesktopProperty(Toolkit.java:1734)
- locked sun.awt.windows.WToolkit@13835b4
javax.swing.UIManager.<clinit>(UIManager.java:384)
javax.swing.JPanel.updateUI(JPanel.java:109)
javax.swing.JPanel.<init>(JPanel.java:69)
javax.swing.JPanel.<init>(JPanel.java:92)
javax.swing.JPanel.<init>(JPanel.java:100)
javax.swing.JRootPane.createGlassPane(JRootPane.java:527)
javax.swing.JRootPane.<init>(JRootPane.java:347)
javax.swing.JFrame.createRootPane(JFrame.java:260)
javax.swing.JFrame.frameInit(JFrame.java:241)
javax.swing.JFrame.<init>(JFrame.java:164)

CuppoJava

unread,
Dec 31, 2008, 1:40:13 PM12/31/08
to Clojure
After some more tinkering, I think the problem lies somewhere in the
way Emacs handles IO from the buffers.

1) The System command prompt works perfectly.
2) Inferior-Lisp mode hangs
3) Slime hangs
4) Running a windows shell from within Emacs, and running Java from
within the shell also hangs.

Symptom 4 leads to me think that the problem doesn't lie in Slime or
clojure-mode or Java.

CuppoJava

unread,
Dec 31, 2008, 1:44:19 PM12/31/08
to Clojure
And Xemacs has the same problem... so it might be a problem with
Windows then.... =(

David

unread,
Feb 5, 2009, 4:52:51 AM2/5/09
to Clojure
I've got the same problem as srolls24 and CuppoJava on Windows XP,
using Emacs 23
and versions of Clojure, Slime and Swank fetched today.

Also, when starting Slime, it opens a connection to *inferior-lisp*,
but keeps polling
for Swank until I hit return in the inferior-lisp buffer. After that,
it very quickly connects
the slime-repl.

Any thoughts?

Shawn Hoover

unread,
Feb 5, 2009, 9:14:12 AM2/5/09
to clo...@googlegroups.com
David, I had that problem on Windows XP as well. I can't figure out the real issue, but it started when Clojure's Ref.java stopped calling UUID.randomUUID. I had to patch swank-clojure like this to work around it:
http://bitbucket.org/shoover/clojure-box-swank-clojuremq/src/11bec919b978/hack-repl-hang

The current release of Clojure Box (http://clojure.bighugh.com) contains that change.

Shawn

srol...@gmail.com

unread,
Feb 11, 2009, 2:02:40 PM2/11/09
to Clojure
On Feb 5, 1:52 am, David <dsieg...@yahoo.com> wrote:
> I've got the same problem assrolls24and CuppoJava on Windows XP,
> using Emacs 23
> and versions of Clojure, Slime and Swank fetched today.
>
> Also, when starting Slime, it opens a connection to *inferior-lisp*,
> but keeps polling
> for Swank until I hit return in the inferior-lisp buffer. After that,
> it very quickly connects
> the slime-repl.
>
> Any thoughts?

I just upgraded to JDK 1.6.0_12 (from 1.6.0_05) and the problem of
swing hanging no longer occurs.

David

unread,
Feb 13, 2009, 1:41:04 AM2/13/09
to Clojure
Here's my experience with 1.6.0_12:

When I run

(load-file "celsius.clj")
(celsius/celsius)

from a REPL in a Cygwin rxvt, the problem recurs as before:

The Swing window comes up, but input is not echoed in the swing window
until I hit return in
the rxvt window.

If I use a cmd shell, I don't have the problem.

SLIME with the emacs version I'm using, 23.0.0.1 (i386-mingw-
nt5.1.2600), still has the problem.

Can anyone recommend an Emacs version that does not exhibit the
problem?
A Cygwin terminal that doesn't have the problem?
Reply all
Reply to author
Forward
0 new messages