Do I Need to Worry About Threading?

107 views
Skip to first unread message

johnnar...@gmail.com

unread,
Feb 24, 2015, 2:22:17 PM2/24/15
to lanterna...@googlegroups.com
Hi,

I've written a Lanterna application that works very nicely. Everything is modal, and I only use the Main thread (the one the JVM invokes your main() method on).

Specifically, I'm not making explicit use of SwingUtilities.invokeLater() anywhere.

I note in the source code that Lanterna is using SwingUtilities.invokeLater() internally to perform certain UI-related activities.

Anyway, I was just looking for confirmation that I'm doing it "right" and that I don't have to worry about threading at the application level (unless, of course, I need to spawn some asynchronous background activity - currently, not the case).

I do have one anomaly that puzzles me. On a Windows 8 system (only), when my application first starts, the Main Window (created by Lanterna) is empty - white. However, if you resize the window (by dragging the borders) the contents of the window paint and everything is fine after that.

I'm at a loss to explain this odd behavior, and I guess I was just wondering if perhaps I'm doing something wrong in the way I'm using or interfacing with Lanterna.

Martin Berglund

unread,
Feb 24, 2015, 6:43:31 PM2/24/15
to lanterna...@googlegroups.com
In general, Lanterna 2.x is not thread safe, but Lanterna 3.x (still in alpha) is intended to be. For Lanterna 2, there's a similar method to SwingUtilities.invokeLater() on the GUIScreen class that can run code asynchronously on the same thread as is running the GUI. Use this whenever you need to update GUI components from other threads.

I've never actually tried Lanterna on Windows 8, but I have tried with Windows 7 and that usually works fine. If the window is initially white until you resize, it sounds like the initial repaint isn't being triggered. You could try to open up Lanterna project in your IDE and run one of the test classes to see if it reproduces there? If it does, can you put a breakpoint inside the SwingTerminal repaint method (paintComponent) and see if it triggers when you open the window?

Thanks,
Martin

--
Det här meddelandet skickas till dig eftersom du prenumererar på gruppen "lanterna-discuss" i Google Grupper.
Om du vill sluta prenumerera på den här gruppen och inte längre få någon e-post från den skickar du ett e-postmeddelande till lanterna-discu...@googlegroups.com.
Fler alternativ finns på https://groups.google.com/d/optout.

johnnar...@gmail.com

unread,
Feb 24, 2015, 6:58:28 PM2/24/15
to lanterna...@googlegroups.com
Thanks, Martin.

Yes, I've run the application on Mac 10.10 (Yosemite), Windows 7 Pro under a VM, and Ubuntu 10.14 under a VM, and have observed no such anomaly.

But on Windows 8, this happens with regularity. I suspect there must be something "different" about the interaction between my application, Lanterna (2.1.7), Java (building on 1.7, executing on 1.8), and Windows 8. Also, this Windows 8 is running native on the hardware (not under a VM). But it's going to be hard finding it!

I'll see if I can set up the test you suggested and get back to you with the results. Aside from the Windows 8 system being on real hardware, I don't have direct access to it. Which, of course, complicates things.

- John
Reply all
Reply to author
Forward
0 new messages