I have created a very simple example to demonstrate the problem. A progressbar is updated all 100ms in a background thread. It seems that every UI.access() call creates a new thread.
The following image shows the thread list in netbeans as a snapshot.
For one user we can see about 220 live threads. But there are >5 new threads per second and >5 old terminates. In VisualVM it is possible to track thread creation.
I hope somebody can help, because this problem can result in unusable web services if there are more than 10 users working.
BR, Axel
Here ist the very simple view source code:
package com.example.threads.views.myview;
import com.vaadin.flow.component.*;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.progressbar.ProgressBar;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
@PageTitle("My View")
@Route("")
public class MyViewView extends Composite<VerticalLayout>
{
public MyViewView()
{
getContent().setWidth("100%");
getContent().getStyle().set("flex-grow", "1");
progressBar.setValue(0.01);
getContent().add(progressBar);
}
@Override protected void onAttach(AttachEvent e)
{
super.onAttach(e);
_mThr = new Thread(() -> _doLoop(e.getUI()), "PROGRESSION");
_mThr.setDaemon(true);
_mThr.start();
}
@Override protected void onDetach(DetachEvent e)
{
try
{
_mThr.interrupt();
_mThr.join();
}
catch (InterruptedException x)
{ Thread.currentThread().interrupt(); }
_mThr = null;
super.onDetach(e);
System.out.println(this + " : detach!");
}
void _doLoop(UI ui)
{ int val = 0;
int off = 1;
try
{
while (ui.isAttached())
{
Thread.sleep(100);
val += off;
float v = 0.01f * val;
ui.access(() -> progressBar.setValue(v));
if (val >= 100)
off = -1;
if (val <= 0)
off = 1;
}
}
catch (InterruptedException x)
{ Thread.currentThread().interrupt(); }
}
private final ProgressBar progressBar = new ProgressBar();
private Thread _mThr;
}