🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #11487

Re: Using the SwingWorker Class for GUI responsiveness

#11487
From: default
Date: Wed, 26 May 1999 00:00
219 lines
9360 bytes
On NT, I find that if I lower the priority of the spawned thread
then it seems to share the workload much better with the spawning
thread. Try the following at the start of the construct method:

public void construct()
{
   Thread current = Thread.currentThread();
   current.setPriority(current.getPriority() - 2);
   ...
}

Also note that SwingWorker is designed to keep the UI responsive
during long running non-GUI tasks. Check that none of the methods
invoked in construct influence the UI. If they do, you'll need to use
Runnables and the SwingUtilities to make the thread communicate.
This is described in the SwingWorker articles on the Swing Connection.

Hope this helps
- Richie


John Blalock wrote:

> I am using the SwingWorker class to allow the GUI to remain responsive while
> a database load occurs in the Borland GridControl.
> However, when I take the menu option off my main frame window, the JInternal
> frame pops up with an empty grid control and then later the data is
> populated.  However, the menu and GUI is frozen until the data is populated.
> If I take the menu option again, the JInternalFrame is not even displayed
> until the data is populated.  I am using the JBuilder 2.01, build
> 002.010.210.000 and the Swing components which came with that release.  I am
> using the Oracle  7 JDBC OCI driver.  What am I doing wrong?  I placed the
> SwingWorker code originally in the "internalFrameOpened" event.  However, it
> looks like the opened event is not even being triggered even though the
> JinternalFrame is opening.  So I moved the code to the JBInit method.
> Below is a listing of the code for the JInternalFrame.  Thanks for your
> reply.  I have bothered with this for several days now.
>
> package PositionManager;
>
> import java.awt.*;
> import java.awt.event.*;
> import java.awt.Dimension;
> import java.sql.*;
> import java.text.*;
> import com.sun.java.swing.*;
> import borland.sql.dataset.*;
> import borland.jbcl.dataset.*;
> import borland.jbcl.control.*;
> import com.sun.java.swing.event.*;
>
> public class MainFrame_ReconReviewList extends JInternalFrame
> {
>   // reference to MainFrame object
>   MainFrame frmMain;
>   public MainFrame_ReconReviewList  frmReconReviewList;
>
>   // dataset for query
>   QueryDataSet qdsReconReviewList = new QueryDataSet();
>   // grid control to display query
>   GridControl gridReconReviewList = new GridControl();
>   // holds parameters for query
>   ParameterRow parmReconDate = new ParameterRow();
>   public String szReconDate;
>   // Column to hold reconciliaton date parameter
>   Column colReconDate = new Column();
>   Column colRCRVW = new Column();
>   Column colACFAN = new Column();
>   Column colIPCUS = new Column();
>   Column colR_SHORT_DESCRIPTION = new Column();
>   Column colN_SHORT_DESCRIPTION = new Column();
>   Column colS_SHORT_DESCRIPTION = new Column();
>   Column colC_PRIMARY_VARIANCE = new Column();
>   Column colC_FUND_VARIANCE = new Column();
>   Column colC_SECONDARY_VARIANCE = new Column();
>   Column colADID = new Column();
>
>   // SQL to get reconciliation review list
>   public static final String GET_RECON_REVIEW_LIST =
>     "SELECT RCRVW, ACFAN, IPCUS, R_SHORT_DESCRIPTION, " +
>     "N_SHORT_DESCRIPTION, S_SHORT_DESCRIPTION, " +
>     "C_PRIMARY_VARIANCE, C_FUND_VARIANCE, C_SECONDARY_VARIANCE, " +
>     "ADID FROM FVPOSREC_RASSELECT WHERE RCRDTE = :RECON_DATE";
>
>   /**
>   * Constructor
>   */
>   public MainFrame_ReconReviewList(String szTitle,
>     boolean bResizable, boolean bClosable, boolean bMaximizable,
>     boolean bIconifiable, Frame parent)
>   {
>     super(szTitle, bResizable, bClosable, bMaximizable, bIconifiable);
>     try
>     {
>       // get reference to MainFrame object
>       frmMain = (MainFrame)parent;
>       frmReconReviewList = this;
>
>       jbInit();
>       pack();
>     }
>     catch (Exception e)
>     {
>       e.printStackTrace();
>     }
>   }
>
>   /**
>   * Initialize components
>   * @param    None
>   * @return   None
>   */
>   private void jbInit() throws Exception
>   {
>     gridReconReviewList.setAutoEdit(false);
>     gridReconReviewList.setAutoInsert(false);
>     gridReconReviewList.setSortOnHeaderClick(true);
>     gridReconReviewList.setReadOnly(true);
>     gridReconReviewList.setSelectRow(true);
>     gridReconReviewList.setShowPopup(false);
>
>     // add the grid to the window
>     getContentPane().add(gridReconReviewList);
>
>     // create new SwingWorker Thread to get reconciliation data
>     final SwingWorker worker = new SwingWorker()
>       {
>         public Object construct()
>         {
>           Object objNull = null;
>           try
>           {
>             // get the reconciliation date from the
>             // combobox on the MainFrame window
>             szReconDate = frmMain.getReconDate();
>
>             // set reconciliation date parameter
>             colReconDate.setColumnName("RECON_DATE");
>             colReconDate.setDataType(borland.jbcl.util.Variant.DATE);
>
> parmReconDate.addColumn("RECON_DATE",borland.jbcl.util.Variant.DATE);
>
>             // convert string date to a real date
>             parmReconDate.setDate("RECON_DATE",
> java.sql.Date.valueOf(szReconDate));
>
>             // set query dataset properties
>             qdsReconReviewList.setResolvable(false);
>             qdsReconReviewList.setEditable(false);
>             qdsReconReviewList.setEnableUpdate(false);
>             qdsReconReviewList.setEnableInsert(false);
>             qdsReconReviewList.setEnableDelete(false);
>             qdsReconReviewList.setReadOnly(true);
>             // sets the SQL for the query dataset
>             qdsReconReviewList.setQuery(
>               new borland.sql.dataset.QueryDescriptor(
>                 frmMain.db, GET_RECON_REVIEW_LIST,
>                 parmReconDate, true, Load.ALL));
>
>             // creates column information
>             colRCRVW.setCaption("Reviewed");
>             colRCRVW.setColumnName("RCRVW");
>             colRCRVW.setWidth(1);
>             colACFAN.setCaption("Customer Account");
>             colACFAN.setColumnName("ACFAN");
>             colACFAN.setWidth(20);
>             colIPCUS.setCaption("CUSIP");
>             colIPCUS.setColumnName("IPCUS");
>             colIPCUS.setWidth(12);
>             colR_SHORT_DESCRIPTION.setCaption("Primary");
>             colR_SHORT_DESCRIPTION.setColumnName("R_SHORT_DESCRIPTION");
>             colR_SHORT_DESCRIPTION.setWidth(6);
>             colN_SHORT_DESCRIPTION.setCaption("Fund");
>             colN_SHORT_DESCRIPTION.setColumnName("N_SHORT_DESCRIPTION");
>             colN_SHORT_DESCRIPTION.setWidth(6);
>             colS_SHORT_DESCRIPTION.setCaption("Secondary");
>             colS_SHORT_DESCRIPTION.setColumnName("S_SHORT_DESCRIPTION");
>             colS_SHORT_DESCRIPTION.setWidth(6);
>             colC_PRIMARY_VARIANCE.setCaption("Primary Variance");
>             colC_PRIMARY_VARIANCE.setColumnName("C_PRIMARY_VARIANCE");
>             colC_PRIMARY_VARIANCE.setDisplayMask("##.######;##.######-");
>             colC_FUND_VARIANCE.setCaption("Fund Variance");
>             colC_FUND_VARIANCE.setColumnName("C_FUND_VARIANCE");
>             colC_FUND_VARIANCE.setDisplayMask("##.######;##.######-");
>             colC_SECONDARY_VARIANCE.setCaption("Secondary Variance");
>             colC_SECONDARY_VARIANCE.setColumnName("C_SECONDARY_VARIANCE");
>             colC_SECONDARY_VARIANCE.setDisplayMask("##.######;##.######-");
>             colADID.setCaption("Administrator");
>             colADID.setColumnName("ADID");
>             colADID.setWidth(15);
>             // sets the columns in the query
>             qdsReconReviewList.setColumns(new Column[] {
>               colRCRVW, colACFAN, colIPCUS, colR_SHORT_DESCRIPTION,
>               colN_SHORT_DESCRIPTION, colS_SHORT_DESCRIPTION,
>               colC_PRIMARY_VARIANCE, colC_FUND_VARIANCE,
>               colC_SECONDARY_VARIANCE, colADID});
>           }
>           catch (borland.jbcl.dataset.DataSetException dse)
>           {
>           }
>           finally
>           {
>             return objNull;
>           }
>         }
>
>         // update the grid with the reconciliation data
>         public void finished()
>         {
>           // attaches the dataset data to the grid
>           gridReconReviewList.setDataSet(qdsReconReviewList);
>           setTitle(szReconDate + " - Recon Analysis Review");
>           frmReconReviewList.invalidate();
>         }
>       };
>   }
> }
>
> blalockj@mindspring.com
Technical Details
Message-ID: <374BB98B.A056E10E@no.spam>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7icb7g$r124@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,b15a82ec982225c8
X-Google-Attributes: gid111d45,public
From: default <default@no.spam>
Subject: Re: Using the SwingWorker Class for GUI responsiveness
Date: 1999/05/26
Message-ID: <374BB98B.A056E10E@no.spam>
X-Deja-AN: 482246055
Content-Transfer-Encoding: 7bit
References: <7icb7g$r124@forums.borland.com>
Organization: Another Netscape Collabra Server User
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing