Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>//You can create a map where you store your tasks, indexed by the id. </p> <pre><code>Map&lt;String,TimerTask&gt; tasks = new HashMap&lt;String,TimerTask&gt;(); </code></pre> <p>You uses a function to generate your named tasks:</p> <pre><code>public TimerTask createTask(String name, final Runnable r){ TimerTask task = new TimerTask(){ public void run(){ r.run(); } } //here, you save it to the HashMap tasks.put(name, task); return task; } </code></pre> <p>// update airport displays when a flight must be shown and another to hide it.</p> <p>Now, to create a task, you create the runnable, like you used to, and creates the name you'd want it to have, for example fligthnumer-show, or flightnumer-hide, and then call that function to create the task.</p> <pre><code>Runnable r= ... //whatever you does here String name = "1234-show"; TimerTask task = createTask( name, r); </code></pre> <p>Now, you can schedule the task,or do whatever you need. besides, your task is saved, so, if you need it again, to cancel it, or to schedule it again, you just need to retrieve it from the hashmap, calling it for its name:</p> <pre><code> TimerTask task = tasks.get("1234-show"); </code></pre> <p>In this example, it is not really useful, but in your real application, if you are, for instance, creating task dinamically, is easy to build a dynamic list of tasks. Say you have to schedule a task to show the info or a new flight, that probably you already did the day before, or probably is a new one. You can check if there is a task already, and if it is, you can use it, otherwise you crete it and save it.</p> <pre><code>//say you have flight number in a var called flightNumber, and you are building a "show" task String name= flightNumber+"show"; TimerTask task = tasks.get(name); //if the task is found, you can use it //instead, f there is not such task, null will be returned, in that case, you create it. if (null== task) { //do al the required stuff, like get the runnable ready, and create the task task = createTask( name, r); } //so here, you can do whatever you need with the task </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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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