You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Brendan cheng <cc...@hotmail.com> on 2012/03/12 18:07:02 UTC

Thread issue

Hi,
I followed the example of background task and built a dialog with a Get task to fetch data.  The task can be ran successfully once and when run the second, it failed with error message:
java.lang.IllegalStateException: this method can only be called from the AWT event dispatch thread, and not from "Thread-11"
I checked with debugger and confirm that the second is still in AWT-EventQueue-0, same as the first.
The dialog box was initialized from BXML file and called by a context menu item.
Any idea what's wrong?
Regards,
Brendan 		 	   		  

Re: Thread issue

Posted by ccp999 <cc...@hotmail.com>.
Hi Lukas,

I found out that I did actually add some UI processes in task thread.

problem solved!

Thanks!

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Thread-issue-tp3819808p3821388.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Thread issue

Posted by ccp999 <cc...@hotmail.com>.
Hi Lukas,

But I believe I use TaskAdapter.  My code:

public void setNewTag(long id, String path) {

		GetAvailableCollaboratorsTask contacttask = new
GetAvailableCollaboratorsTask(
				id, path);

		TaskListener<List&lt;Collaborator>> taskListener = new
TaskListener<List&lt;Collaborator>>() {

			@Override
			public void taskExecuted(
					Task<List&lt;Collaborator>> task) {
				cardPane.setSelectedIndex(1);
				activityIndicator.setActive(false);
				if (task.getResult() != null) {
					collaborators = task.getResult();
					submitButton.setEnabled(true);
				}
			}

			@Override
			public void executeFailed(
					Task<List&lt;Collaborator>> task) {
				cardPane.setSelectedIndex(1);
				submitButton.setEnabled(false);
				activityIndicator.setActive(false);
				errorLabel.setText("Failed to load collaborators! "
						+ task.getFault());
				System.err.println(task.getFault());
			}

		};

		contacttask
				.execute(new TaskAdapter<List&lt;Collaborator>>(
						taskListener));

	}

Do you agree?

Brendan

--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Thread-issue-tp3819808p3821224.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Thread issue

Posted by Lukáš Macháček <cg...@coolmail.cz>.
Hi Brendan,

It's not good approach to modify GUI from Task thread.
I was facing this issue too. You can look here: 
http://mail-archives.apache.org/mod_mbox/pivot-user/201201.mbox/browser
You can use TaskAdapter or ApplicationContext.queueCallback() to 
modify/work with GUI, for example to show loaded data somewhere ;-)

Lukas

Dne 12.3.2012 18:07, Brendan cheng napsal(a):
> Hi,
>
> I followed the example of background task and built a dialog with a 
> Get task to fetch data.  The task can be ran successfully once and 
> when run the second, it failed with error message:
>
> java.lang.IllegalStateException: this method can only be called from 
> the AWT event dispatch thread, and not from "Thread-11"
>
>
> I checked with debugger and confirm that the second is still in 
> AWT-EventQueue-0, same as the first.
>
>
> The dialog box was initialized from BXML file and called by a context 
> menu item.
>
>
> Any idea what's wrong?
>
>
> Regards,
>
>
> Brendan
>