Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:31:18+00:00 2026-06-12T13:31:18+00:00

I have the following situation: 2 swingworkers with session which collect data from the

  • 0

I have the following situation:

2 swingworkers with session which collect data from the database. Now I want to cancel the second swingworker. I do swingworker.cancel(true) and in the done() method from the swingworker I close the session with session.close().

After I have done that I think the swingworker has one sql statement which he is executing but he is cancelled and the session is closed so the following execption occures:

java.lang.NullPointerException
    at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.getResourceRegistry(ConnectionProxyHandler.java:104)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.getResourceRegistry(AbstractStatementProxyHandler.java:73)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.wrapIfNecessary(AbstractStatementProxyHandler.java:150)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:123)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at $Proxy9.executeQuery(Unknown Source)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.scroll(Loader.java:2510)
    at org.hibernate.loader.custom.CustomLoader.scroll(CustomLoader.java:337)
    at org.hibernate.internal.SessionImpl.scrollCustomQuery(SessionImpl.java:1760)
    at org.hibernate.internal.AbstractSessionImpl.scroll(AbstractSessionImpl.java:232)
    at org.hibernate.internal.SQLQueryImpl.scroll(SQLQueryImpl.java:182)
    at de.mudisar.dataloader.SecondarySwingWorker.doInBackground(SecondarySwingWorker.java:71)
    at de.mudisar.dataloader.SecondarySwingWorker.doInBackground(SecondarySwingWorker.java:32)
    at javax.swing.SwingWorker$1.call(SwingWorker.java:277)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at javax.swing.SwingWorker.run(SwingWorker.java:316)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

What can i do to solve the problem. If i cancel the swingworker i want that all sql operations or other things should be cancelled and then close the session.

//EDIT:

Here is my code from my swingworker. This swingworker has its own session:

@Override
protected Void doInBackground() throws Exception {

doMappings();

fetchSQL();


}

private void fetchSQL(){

for(String str : map.keySet()){

    //build sql;
    SQLQuery q = sess.createSQLQuery(query).addEntity("ins", ALL_RSC_DATA.class);
    q.setFetchSize(Integer.valueOf(1000));
    q.setReadOnly(true);
    ScrollableResults results = q.scroll(ScrollMode.FORWARD_ONLY);
    while (results.next()) {

        //processing

    }

}

}

And this is my action (for cancel the swingworker) from my other class which handles the user inputs:

public Action cancelPrimarySwingWorker = new AbstractAction() {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public void actionPerformed(ActionEvent arg0) {
        if(psw != null && !psw.isDone()){
            closeDBConnection(psw.getSession());
            psw.cancel(true);
            psw = null;
            restoreData();
        }
    }
};

For the complete information here my code for closeDBConnection():

@SuppressWarnings("deprecation")
public static void closeDBConnection(Session session) {
    if(session != null){
        try {
            //session.connection().createStatement().execute("SHUTDOWN");
            if(session.isOpen()){
                session.cancelQuery();
                session.clear();
                session.close();
            }
            session = null;
        }
        catch (Exception sqle) {
            logging(sqle);
            System.exit(1);
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:31:19+00:00Added an answer on June 12, 2026 at 1:31 pm
    public void actionPerformed(ActionEvent arg0) {
        if(psw != null && !psw.isDone()){
            closeDBConnection(psw.getSession());
            psw.cancel(true);
            psw = null;
            restoreData();
        }
    

    This sure looks to me like you’re closing the db connection while the reader thread is still running, which would probably result in exactly what you’re seeing. You need to restructure things so the reader thread responds to the cancel and closes the connection itself in a finally block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation which generates a OID error when retriving data from
I have following situation - Have a MongoService class, which reads host, port, database
I have the following situation: I need to save data from an Intent's putExtra
For some reason, I have following situation: Now I want to get rid of
I have following Situation, Server A sends some data (HTML form) to server B,
I have the following situation. We want an reputation table to evaluate Users And
I have the following situation: An Conversations entity/table which has multiple Tags associated to
I have the following situation and I'm expecting some expert advise from SO folks.
I have the following situation: From within a view controller, I go about creating
I have the following situation. I have a database of transactions about multiple contracts.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.