Note that there are some explanatory texts on larger screens.

plurals
  1. POCall a non-static method from ShutdownHook
    primarykey
    data
    text
    <p>I need to call the method a non static method <code>removeLocksOnExit()</code> from a ShutdownHook. the method is declared in te same class where the main is.</p> <p>In the main i have the following code:</p> <pre><code>//final Thread mainThread = Thread.currentThread(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { // remove lock file... removeLocksOnExit(); } }); </code></pre> <p>The removeLocks() cannot be decared static and therefore i canot call it directly from the new thread.</p> <p>The main class contains However an action listners over the windows closing which calls the method as well. Here is an extract of the code:</p> <pre><code>addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (exit() == 0) { removeLocksOnExit(); log.info("END"); System.exit(0); } } }); </code></pre> <p>Perhaps i could then from the addShutdownHook fire the windows closing event. and this one will call the function fore me. ( Or create a special event for the purpose to be cached...</p> <p>Is it feasible?? If yes how would you fire the event??</p> <p>to have a better understanding here is the structure of my class:</p> <pre><code>public class IEPLC_Tool extends JFrame{ removeLocksOnExit(){ .... ... } public static void main(String[] args) { ............... ......... //final Thread mainThread = Thread.currentThread(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { // remove lock file... removeLocksOnExit(); } }); } final IEPLC_Tool inst = new IEPLC_Tool(args); IEPLC_Tool(String[] args) { super(CustomPathModel.IEPLC_TITLE); setResizable(false); // FIXME find a way to auto size inner xml-editor addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (exit() == 0) { removeLocksOnExit(); log.info("END"); System.exit(0); } } }); setLookFeel(); initAdminStatus(); initGUI(); addFesaToolActionListener(this); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload