Changeset 7755


Ignore:
Timestamp:
Nov 26, 2019, 2:03:58 PM (4 years ago)
Author:
Nicklas Nordborg
Message:

References #2195: "Timer already cancelled" when trying to log in

Added try/catch in the ThreadTimerTask implementation. This should prevent the built-in timer in BASE from stopping and hopefully prevent problems caused by that.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.15-stable/src/core/net/sf/basedb/util/timer/ThreadTimerTask.java

    r6684 r7755  
    4343{
    4444
     45  private static final org.slf4j.Logger log =
     46    org.slf4j.LoggerFactory.getLogger(ThreadTimerTask.class);
     47
    4548  private final TimerTask task;
    4649  private final boolean allowMultiple;
     
    6972  public final synchronized void run()
    7073  {
    71     Thread t = null;
    72     if (allowMultiple)
     74    try
    7375    {
    74       // We just create another thread
    75       t = new Thread(task);
    76     }
    77     else if (!isExecuting)
    78     {
    79       // Create a new thread that also manages the isExecuting flag
    80       isExecuting = true;
    81       t = new Thread(
    82         new Runnable()
    83         {
    84           @Override
    85           public void run()
     76      Thread t = null;
     77      if (allowMultiple)
     78      {
     79        // We just create another thread
     80        t = new Thread(task);
     81      }
     82      else if (!isExecuting)
     83      {
     84        // Create a new thread that also manages the isExecuting flag
     85        isExecuting = true;
     86        t = new Thread(
     87          new Runnable()
    8688          {
    87             try
     89            @Override
     90            public void run()
    8891            {
    89               task.run();
    90             }
    91             finally
    92             {
    93               isExecuting = false;
     92              try
     93              {
     94                task.run();
     95              }
     96              finally
     97              {
     98                isExecuting = false;
     99              }
    94100            }
    95101          }
    96         }
    97       );
     102        );
     103      }
     104      else
     105      {
     106        // Do not allow multiple thread to execute the task
     107      }
     108      // Start the thread
     109      if (t != null) t.start();
    98110    }
    99     else
     111    catch (Throwable t)
    100112    {
    101       // Do not allow multiple thread to execute the task
     113      log.error("Failed to start task: " + task, t);
    102114    }
    103     // Start the thread
    104     if (t != null) t.start();
    105115  }
    106116  @Override
Note: See TracChangeset for help on using the changeset viewer.