1

One of our Java based Swing applications has a class which creates an java.util.concurrent.ExecutorService instance used to run SwingWorkers. Before the executor service is returned, a custom PropertyChangeListener is added to the instance of sun.awt.AppContext to shutdown the executor service when the AppContext is 'disposed'.

I am investigating all hurdles that may arise when we migrate the code base from Java 8 to 15. The class AppContext is no longer available from Java 9 on.

Is there a suitable replacement mechanism in current Java JDK to recreate this?

The current code looks something like this:

ExecutorService service = new ThreadPoolExecutor(...); 
final ExecutorService es = service;

AppContext.getInstance().addPropertyChangeListener(
    AppContext.DISPOSED_PROPERTY_NAME,
    new PropertyChangeListener()
    {
        @Override
        public void propertyChange(PropertyChangeEvent pce)
        {
            // here some code, where we extract executor service from property change event
            ExecutorService executorService = ...;
            AccessController.doPrivileged(new PrivilegedAction<Void>()
            {
                executorService.shutdown();
            });
        }
    }
);
4

0 回答 0