I am using JDK 1.8 on Windows 10 64-bit with 8 GB of RAM.
I have a Swing application.
In the application I query a DB2 database.
The query returns a list of database table names and query criteria for each table.
These tables exist in a separate, SQL Server Express database.
My Swing application creates a separate JComboBox
for each SQL Server Express database table and queries that table using the received criteria and populates the JComboBox
model with the query results.
I loop through the results of the DB2 query and for each row I create a new JComboBox
and launch a new SwingWorker
to query the SQL Server Express database.
Originally my app ran with JDK 1.5 on Windows 7.
Of-course SwingWorker
was not part of JDK in version 1.5 so I used a third party implementation.
The original works fine, however after migrating to JDK 1.8 on Windows 10, it takes much more time for all of this initialization to complete.
Using VisualVM, the increase in time is due to the SwingWorker
threads waiting in method park()
of class LockSupport
.
I measured the time taken to perform each individual step in the process and most of them take a few hundredths of a second to complete with the overall time for all the steps not exceeding three seconds.
I tried using the SwingWorker
implementation from my JDK 1.5 app in the JDK 1.8 version but the time taken did not change.
How can I discover what is causing some of the SwingWorker
threads to spend around 6 seconds in method park()
?
Alternatively, how can I change my design in order to avoid this problem?
Partial [pseudo] code...
JPanel panel = new JPanel();
Connection db2Conn = // Connect to DB2
Statement s = db2Conn.createStatement();
ResultSet rs = s.executeQuery("SQL query");
while (rs.next()) {
new ListTask(panel, /* data from 'rs' */).execute();
}
class ListTask extends SwingWorker<Void, Void> {
// JComboBox will be added to this. See method 'done()'
private JPanel panel;
// Name of table in database.
private String tableName;
// Criteria for querying 'tableName'.
private List<String> criteria;
// Results of query.
private Object[] results;
public ListTask(JPanel aPanel, String table, List<String> where) {
panel = aPanel;
tableName = table;
criteria = where;
}
protected void doInBackground() {
// Populate "results"
return null;
}
protected void done() {
JComboBox<Object> combo = new JComboBox(results);
panel.add(combo);
}
}
VisualVM screen capture: