Home > Java Cannot > Java Cannot Call Invokeandwait From The Event Dispatcher Thread

Java Cannot Call Invokeandwait From The Event Dispatcher Thread

I WAS using a Thread, then I used SwingWorker but both of them lock up my GUI... at com.acme.ui.components.MyTextAreaComponent$MyDocumentListener.insertUpdate(MyTextAreaComponent.java:916) at javax.swing.text.AbstractDocument.fireInsertUpdate(Unknown Source:-1) at javax.swing.text.AbstractDocument.handleInsertString(Unknown Source:-1) at javax.swing.text.AbstractDocument$DefaultFilterBypass.replace(Unknown Source:-1) at javax.swing.text.DocumentFilter.replace(Unknown Source:-1) at com.acme.ui.components.FilteredDocument$InputDocumentFilter.replace(FilteredDocument.java:204) at javax.swing.text.AbstractDocument.replace(Unknown Source:-1) at javax.swing.text.JTextComponent.replaceSelection(Unknown Source:-1) at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(Unknown Source:-1) at javax.swing.SwingUtilities.notifyAction(Unknown Source:-1) at javax.swing.JComponent.processKeyBinding(Unknown Source:-1) But they deliberately omitted an equivalent method to invokeAndWait because it's very difficult to use properly.) The reason is fairly straightforward to derive from first principles. It's being called from My-Thread. –John Vint Dec 3 '13 at 14:39 If invokeAndWait is called from a "wrapper thread" then it's not being called on the EDT anymore. news

Bug145975 - [65cat] Error: Cannot call invokeAndWait from the event dispatcher thread Summary: [65cat] Error: Cannot call invokeAndWait from the event dispatcher thread Status: RESOLVED FIXED Product: contrib Classification: Unclassified Component: In first part we will mostly focus on invokeLater and will find answers to questions like What is invokeLater, how to use invokelater in java swing, example of invokelater in swing Rather put your rendering function in this Runnable directly. What is the most someone can lose the popular vote by but still win the electoral college?

The OP has said that doing so causes other problems. Join them; it only takes a minute: Sign up Unresponsive threading involving Swing and AWT-EventQueue up vote 9 down vote favorite 3 I have an application that is unresponsive and seems Since this infinite loop is on the EDT, the GUI can never be repainted; hence it locks up.

Join them; it only takes a minute: Sign up SwingUtilities.invokeAndWait not running up vote 1 down vote favorite The code within the run() method is not being executed. Are you trying to manipulate Swing components off of the EDT (with your setEditFields and similar method calls)? It seems to suggest that it is kind of a hit or miss thing. –Elliott Oct 14 '11 at 21:30 @Elliott yes any function can be called from any I have the code shown below.

To fix this you must change the code that calls the method. An important point to note is that in case if the run method of Runnable task throws any exception then AWT Event dispatcher thread will unwind and not the current thread. Description ranbato 2008-09-02 22:47:20 UTC Build: NetBeans IDE Dev (Build 200809020201) VM: Java HotSpot(TM) Client VM, 10.0-b23, Java(TM) SE Runtime Environment, 1.6.0_07-b06 OS: Windows XP, 5.1, x86 User Comments: I hit Thus all the code posted runs in the EDT (Event Dispatch Thread) and it refuses to invokeAndWait because that causes an inherent deadlock. (Actually, it could be turned into an invoke-immediate

When I press the button the run() method is not called. Theme: Flat 1.7.6 by Themeisle. And in your example it seems that you are in the EDT. What is invokeLater in Java Swing The invokeLater() is a method in java on swing package and belongs to SwingUtilities class.

How to reply? https://coderanch.com/t/233732/java/call-invokeAndWait-invokeLater I think while posting your GUI rendering task to Event Queue using a synchronized function like enderOnEDT as you have said in your comment, then I don't see any reason for there was also lots of followup in terms of blocking and how invokeAndWait achieves blocking etc. Show that the square matrix A is invertible What is the most someone can lose the popular vote by but still win the electoral college?

So, using invokeLater should help run the operation on the EDT without blocking it. http://bestimageweb.com/java-cannot/java-cannot-invert-matrix.php How does InvokeAndWait works in Java Swing If you look at the signature of invokeAndWait method you will see that it takes a Runnable object and run method of that Runnable How to use Fork Join in Java 1.7 - Tutorial with E... It sends a Runnable object to the GUI thread where it will be executed.

Edit: As it turns out, the actual problem is this loop: synchronized(performedAction){ while(!hasPerformedAction()){ try { performedAction.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } setPerformedAction(false); } Since there is only one According to the OP's comments on this answer, Yes, renderOnEDT is synchronized on something way up in the call stack, the com.acme.persistence.TransactionalSystemImpl.executeImpl method which is synchronized. Some of my other tutorial in Java How do you avoid deadlock in Java How to use Comparator and Comparable in Java? More about the author Fixed in d459af916816 - but again, the feature doesn't work quite as well as before because after invoking Retry you have to press Enter or F7 to complete the step.

Variable argument or Varargs methods from Java 5 w... 10 examples of displaytag in JSP, Struts and Sprin... Even this is rather an understatement; I'd have preferred that it say something like, "If you use invokeAndWait, the thread that calls invokeAndWait must not hold any locks that other threads September 14, 2011 at 10:02 PM Anonymous said...

Will boring a cylinder affect its longevity thereafter?

But in general, you should avoid synchronizing and long running operations on the EDT. It mustn't make any assumptions based on results from code block 1, since those results might be out of date. What is the most efficient & fastest way to speed up the installation of packages with thousands of items? I changed to code to display an error dialog and return from that method instead of exiting.

If we can't remove locks, and we can't change to invokeLater, we're left with calling invokeAndWait safely. BTW, the fix isn't to change it to the invokeLater() method. Why is the 'You talking to me' speech from the movie 'Taxi Driver' so famous? click site I am seen in darkness and in light, What am I?

Where else is the TransactionalSystemImpl instance being used (with synchronized entry)? Browse other questions tagged java swing event-handling or ask your own question. This would make your scenario a bit easier, though it probably is not the root cause of your problem. –Matthias Dec 5 '13 at 11:38 Thanks for awarding the Thank you!   BUT.

The problem occurs when it can't get the lock because the lock's holder is deadlocked on the EDT. current community chat Stack Overflow Meta Stack Overflow your communities Sign up or log in to customize your list. Possible repercussions from assault between coworkers outside the office Check if an item is in a nested list Why is (a % 256) different than (a & 0xFF)? How do I make an alien technology feel alien?