Foros de discusión

Vaadin Portlet in Liferay Thread Issue - Vaadin 7.2.0

Richard Guerrini, modificado hace 9 años.

Vaadin Portlet in Liferay Thread Issue - Vaadin 7.2.0

New Member Mensajes: 19 Fecha de incorporación: 28/10/13 Mensajes recientes
Hello all,

I am trying to open a window, kick off a new thread that runs a query (while some kind of progress bar is running), and have the option of killing the thread if needed via a button. I want to be able to stop the execution on the main thread so that it is waiting for the result of the query running in the new thread.

Here is the code that created the new window:

Window sw = new Window("Receipt");
        QueryRun qr = new QueryRun(this.transManager,transInfo,sw,myUi);
        sw.setImmediate(true);
        sw.setClosable(false);
        sw.setModal(true);
        sw.setContent(qr);
        sw.center();
        sw.setHeight("250px");
        sw.setWidth("350px");
        myUi.addWindow(sw);Code contained in the QueryRun class:


Here is the code in the window (omitting some parts):


public QueryRun(TransactionManager transManager, TransactionInfo transInfo, final Window wi, MyPortletUI mUi)
.
.
.
this.mUi_This.setPollInterval(1000);
final Thread tr = new Thread(new Loader());
tr.start();
.
.
.
.
.
class Loader extends Thread {
        @Override
        public synchronized void run() {
            try {
                // Run the query here
            } catch (Exception e) {
            }
            mUi_This.access(new Runnable() {
                @Override
                public void run() {
                    addComponent(new Label("This is the real content"));
                    mUi_This.setPollInterval(-1);
                    //wi_This.close();
                }
            });
        }

   
}


The polling aspect works correctly, the window is getting updated from the new thread. I just cannot get the main thread to wait for the new thread. I have also tried the typical Java "wait" and "notify" approach with the new thread being synchronized, but I am getting issues with when the window appears (as if it is not polling at all).

Thanks in advance!


<liferay.version>6.0.6</liferay.version>
<vaadin.version>7.2.0</vaadin.version>
thumbnail
David H Nebinger, modificado hace 9 años.

RE: Vaadin Portlet in Liferay Thread Issue - Vaadin 7.2.0

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
Main thread should never be waiting, that's the thread responsible for servicing the UI. It's the main thread that invokes the runnables queued up via the access() method.

Personally I've always had to use the Refresher component to handle the background thread updates to the UI.

My UI class implements com.github.wolfie.refresher.Refresher.RefreshListener, then I add the implementation:

/**
 * @see com.github.wolfie.refresher.Refresher.RefreshListener#refresh(com.github.wolfie.refresher.Refresher)
 */
public void refresh(final Refresher source) {
	VaadinPortletService.getCurrent().runPendingAccessTasks(VaadinPortletSession.getCurrent());
}


By using the refresher this way, the browser calls back to the vaadin portlet on a regular basis (whatever you time it as), then this line of code ensures the access runnables are executed and the dom updated.
Richard Guerrini, modificado hace 9 años.

RE: Vaadin Portlet in Liferay Thread Issue - Vaadin 7.2.0

New Member Mensajes: 19 Fecha de incorporación: 28/10/13 Mensajes recientes
Hi David,

Thanks for your reply.

What I actually ended up doing was add a Window close listener to the main thread, like this:


sw.addCloseListener(new Window.CloseListener() {
            
			@Override
			public void windowClose(CloseEvent e) {
				
				gl.addComponent(new TransactionTable(qr.getTransactions(), transInfo, role, rlf ));
			}
        });


This way when the Window that creates the thread and runs the query closes, the main thread resumes and I am able to view the results from the query.

Thanks for you reply anyway, I will look into the Refresher Listener next time!