Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

IPluginContext.openChart() - java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
 Post subject: IPluginContext.openChart() - java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread Post rating: 0   New post Posted: Sat 25 Nov, 2017, 09:44 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
While trying to open chart from a button-click in my plugin I receive this exception
java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
   at java.awt.EventQueue.invokeAndWait(Unknown Source)
   at java.awt.EventQueue.invokeAndWait(Unknown Source)
   at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
   at com.dukascopy.api.impl.connect.bc.openChart(L:258)
   at jforex.experimental.OpenChartBugDemoPlugin$1.actionPerformed(OpenChartBugDemoPlugin.java:35)

Please fix.
Sample code to reproduce the problem is attached.


Attachments:
OpenChartBugDemoPlugin.java [1.67 KiB]
Downloaded 166 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: IPluginContext.openChart() - java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread Post rating: 0   New post Posted: Mon 27 Nov, 2017, 09:52 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Chart should be opened from plugin thread by calling IPluginContext.executeTask(task);


Attachments:
OpenChartBugDemoPlugin.java [2.12 KiB]
Downloaded 162 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: IPluginContext.openChart() - java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread Post rating: 0   New post Posted: Mon 27 Nov, 2017, 15:42 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
API Support wrote:
Chart should be opened from plugin thread by calling IPluginContext.executeTask(task);
'OnClick' handler is executed NOT in plugin thread, it is executed in the AWT Event Dispatcher thread - and the problem is caused by the 'SwingUtilities.invokeAndWait()' in 'openChart()'.
Correct implementation of 'openChart()' method would be checking if we are already in Event Dispatcher thread using method 'EventQueue.isDispatchThread()' and, if yes, executing same code without wrapping into 'SwingUtilities.invokeAndWait()'

The recommendation you provide is actually a workaround, which i'm already using - calling openChart() from any non-Event-Dispatcher thread does work, but this way is not natural.


 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com