Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1902 connectés 

 


 Mot :   Pseudo :  
 
 Page :   1  2
Page Suivante
Auteur Sujet :

[Java] Multithreading et gestion des exceptions

n°810201
Cherrytree
cn=?
Posté le 29-07-2004 à 17:11:49  profilanswer
 

Reprise du message précédent :

Jubijub a écrit :

certain amouth of time to complete = certain amount of time to complete
 
(petite typo n<->h et invertion avec t)


Oui bon dans ce cas, on a aussi des curently, betwen, regulary, it's execution, et periodicaly (pas sûr mais presque que ça prend 2 'l's).

mood
Publicité
Posté le 29-07-2004 à 17:11:49  profilanswer
 

n°810219
Jubijub
Parce que je le VD bien
Posté le 29-07-2004 à 17:20:48  profilanswer
 

oh l'autre comment y dénonce !!!! :D
 
--> au fait comment tu fais toi qd :  
- ta gui est supposée lancer un thread indépendant, et que tu veux pas qu'elle freeze
- tu veux malgré tout récupérer ce qu'a produit le thread
 
nraynaud a dit l'avoir dit ici, mais j'ai pas trouvé/compris où


---------------
Jubi Photos : Flickr - 500px
n°810242
nraynaud
lol
Posté le 29-07-2004 à 17:33:56  profilanswer
 

jubi > http://forum.hardware.fr/hardwaref [...] tm#t805573


---------------
trainoo.com, c'est fini
n°811585
Cherrytree
cn=?
Posté le 30-07-2004 à 21:44:20  profilanswer
 

L'est vraiment bien le NetworkScheduler. :jap: J'apprends beaucoup en le lisant. Mais je sens bien que je ne suis pas capable de faire un tel engin moi-même.
 
Vraiment chapeau. Combien de temps pour le réaliser ?


Message édité par Cherrytree le 30-07-2004 à 21:44:37

---------------
Le site de ma maman
n°811614
nraynaud
lol
Posté le 30-07-2004 à 22:29:32  profilanswer
 

cerisier > je sais pas comment te dire, mais il est nul ce truc, il fait 3 lignes, il n'est le fruit d'aucun travail d'ananlyse poussé, tout est extrèmement basique dedans, il fonctionne et on l'oublie.
 
Va voir les DecoratedText, ils ont vécus, ils sont encore un peu bloated, d'ici 2 révisions, ça devrait aller mieux.


---------------
trainoo.com, c'est fini
n°811617
Cherrytree
cn=?
Posté le 30-07-2004 à 22:36:34  profilanswer
 

:lol: Un truc nul qui m'émerveille. C'est ça la belle vie. Je regarderais les DecoratedText.


---------------
Le site de ma maman
n°811627
nraynaud
lol
Posté le 30-07-2004 à 22:58:32  profilanswer
 

tiens, tu m'as fait douter, j'ai été y voir, je suis en train de le nettoyer.


Message édité par nraynaud le 30-07-2004 à 22:58:48

---------------
trainoo.com, c'est fini
n°811673
nraynaud
lol
Posté le 31-07-2004 à 00:30:02  profilanswer
 

Code :
  1. /*
  2. * Created on 23 avr. 2004
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Library General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public
  14. * License along with this library; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 02111-1307, USA.
  17. */
  18. package jcoincoin.net;
  19. import java.util.HashMap;
  20. import java.util.HashSet;
  21. import java.util.LinkedList;
  22. import java.util.Map;
  23. import java.util.NoSuchElementException;
  24. import java.util.Set;
  25. import java.util.Timer;
  26. import java.util.TimerTask;
  27. /**
  28. * @author nraynaud
  29. *  
  30. * Represents a very simple time slicer. Using this avoid having lots of threads
  31. * in the system using the network randomly.
  32. *  
  33. * Units of work are represented by the Task interface. If the work takes more
  34. * than a certain amouth of time to complete, a second Thread is created to
  35. * continue fetching work out of the queue.
  36. *   
  37. */
  38. public class NetworkScheduler {
  39.     /**
  40.      * the time a task can run before we start a second thread to process the
  41.      * queue.
  42.      */
  43.     private static final int MAX_EXECUTION_TIME = 10000;
  44.     /**
  45.      * the great task queue
  46.      */
  47.     private LinkedList taskQueue = new LinkedList();
  48.     /**
  49.      * the big timer used for periodicity.
  50.      */
  51.     private Timer timer = null;
  52.     /**
  53.      * the hashmap Task -> PeriodicTask of the curently registered periodic
  54.      * tasks.
  55.      */
  56.     private final Map periodicTasksMap = new HashMap();
  57.     /**
  58.      * number of threads to process the task queue.
  59.      */
  60.     static private volatile int threadNumber = 0;
  61.     static private synchronized void incrementThreadnumber() {
  62.         threadNumber++;
  63.     }
  64.     static private synchronized void decrementThreadnumber() {
  65.         threadNumber--;
  66.     }
  67.     private Set executingTasks = new HashSet();
  68.     /**
  69.      * current main executor.
  70.      */
  71.     private WorkingThread currentExecutor;
  72.     /**
  73.      * the big one scheduler
  74.      */
  75.     private static NetworkScheduler instance = null;
  76.     private TimerTask timeoutTask;
  77.     public static synchronized NetworkScheduler getInstance() {
  78.         if (instance == null)
  79.             instance = new NetworkScheduler();
  80.         return instance;
  81.     }
  82.     private NetworkScheduler() {
  83.     }
  84.     private void alertExecutor() {
  85.         assert (Thread.holdsLock(this));
  86.         getCurrentExecutor().alertNewMessage();
  87.     }
  88.     /**
  89.      *  
  90.      * @return the current executor, creating a new one if there is none.
  91.      */
  92.     private synchronized WorkingThread getCurrentExecutor() {
  93.         if (currentExecutor == null)
  94.             currentExecutor = new WorkingThread();
  95.         return currentExecutor;
  96.     }
  97.     private synchronized void setCurrentExecutor(WorkingThread ex) {
  98.         currentExecutor = ex;
  99.     }
  100.     private synchronized void timeoutCurrentExecutor() {
  101.         System.out.println("notice : task timeout : "
  102.                 + String.valueOf(getCurrentExecutor().getCurrentTask()));
  103.         getCurrentExecutor().timeout();
  104.         setCurrentExecutor(new WorkingThread());
  105.     }
  106.     private synchronized Task getTask() {
  107.         try {
  108.             return (Task) taskQueue.removeFirst();
  109.         } catch (NoSuchElementException e) {
  110.             return null;
  111.         }
  112.     }
  113.     /**
  114.      * Immediately enqueue the given task for execution.
  115.      *  
  116.      * @param task
  117.      *            the task to enqueue.
  118.      */
  119.     public synchronized void enqueue(Task task) {
  120.         taskQueue.addLast(task);
  121.         alertExecutor();
  122.     }
  123.     /**
  124.      * Enqueue th task to be executed exactly at the end of the currently
  125.      * executing task. This means that unfair enqueuing are unfair betwen
  126.      * themselves too, this is not a priority scheme.
  127.      *  
  128.      * @param task
  129.      *            the work
  130.      */
  131.     public synchronized void unfairlyEnqueue(Task task) {
  132.         taskQueue.addFirst(task);
  133.         alertExecutor();
  134.     }
  135.     /**
  136.      * Schedules the given task to be enqueued regulary at the given period.
  137.      * Exactly, the task is sceduled to be reenqueued period millisecond after
  138.      * the end of it's execution. The task is first immediately enqueued.
  139.      *  
  140.      * @param task
  141.      *            the work unit.
  142.      * @param period
  143.      *            the period in milliseconds.
  144.      */
  145.     synchronized public void periodicalyEnqueue(final Task task,
  146.             final long period) {
  147.         PeriodicTask pTask = new PeriodicTask(task, period);
  148.         periodicTasksMap.put(task, pTask);
  149.         enqueue(pTask);
  150.     }
  151.     synchronized public void changePeriod(Task task, final long newPeriod) {
  152.         PeriodicTask pTask = (PeriodicTask) periodicTasksMap.get(task);
  153.         if (pTask == null)
  154.             throw new IllegalArgumentException(
  155.                     "the given task is not in the system" );
  156.         else
  157.             pTask.setPeriod(newPeriod);
  158.     }
  159.     synchronized public void removePeriodicTask(Task task) {
  160.         if (periodicTasksMap.remove(task) == null)
  161.             throw new IllegalArgumentException(
  162.                     "the given task is not in the system" );
  163.     }
  164.     /**
  165.      * Enqueues the given task after the given period.
  166.      *  
  167.      * @param task
  168.      *            the task to reenqueue
  169.      * @param delay
  170.      *            the delay to wait in milliseconds.
  171.      */
  172.     private void enqueueDelayed(final Task task, final long delay) {
  173.         getTimer().schedule(new TimerTask() {
  174.             public void run() {
  175.                 enqueue(task);
  176.             }
  177.         }, delay);
  178.     }
  179.     private synchronized Timer getTimer() {
  180.         if (timer == null)
  181.             timer = new Timer(true);
  182.         return timer;
  183.     }
  184.     /**
  185.      * Excutor listening infrastructure.
  186.      *  
  187.      * @param t
  188.      * @param e
  189.      */
  190.     private synchronized void startTask(Task t, WorkingThread e) {
  191.         assert (e == getCurrentExecutor());
  192.         timeoutTask = new TimerTask() {
  193.             public void run() {
  194.                 timeoutCurrentExecutor();
  195.             }
  196.         };
  197.         getTimer().schedule(timeoutTask, MAX_EXECUTION_TIME);
  198.     }
  199.     /**
  200.      * Executor listening infrastructure.
  201.      *  
  202.      * @param t
  203.      * @param e
  204.      */
  205.     private synchronized void endTask(Task t, WorkingThread e) {
  206.         if (e == getCurrentExecutor())
  207.             timeoutTask.cancel();
  208.     }
  209.     /**
  210.      * Periodic Task proxy.
  211.      *  
  212.      * @author nraynaud
  213.      *   
  214.      */
  215.     private class PeriodicTask implements Task {
  216.         private final Task task;
  217.         volatile private long period;
  218.         /**
  219.          * @param task
  220.          * @param period
  221.          */
  222.         public PeriodicTask(final Task task, long period) {
  223.             this.task = task;
  224.             this.period = period;
  225.         }
  226.         public void work() {
  227.             try {
  228.                 task.work();
  229.             } finally {
  230.                 synchronized (NetworkScheduler.this) {
  231.                     if (periodicTasksMap.get(task) == this)
  232.                         enqueueDelayed(this, period);
  233.                 }
  234.             }
  235.         }
  236.         public String toString() {
  237.             return task.toString() + " (made periodic)";
  238.         }
  239.         public void onException(Exception e) {
  240.             task.onException(e);
  241.         }
  242.         public boolean equals(Object other) {
  243.             return task.equals(other);
  244.         }
  245.         public int hashCode() {
  246.             return task.hashCode();
  247.         }
  248.         /**
  249.          * @return Returns the period.
  250.          */
  251.         synchronized public long getPeriod() {
  252.             return period;
  253.         }
  254.         /**
  255.          * @param period
  256.          *            The period to set.
  257.          */
  258.         synchronized public void setPeriod(long period) {
  259.             this.period = period;
  260.         }
  261.     }
  262.     /**
  263.      * @author nraynaud
  264.      *  
  265.      * The executor is responsible for fetching tasks and executing them. If it
  266.      * as been timeouted, it will die after finishig the current task.
  267.      */
  268.     private final class WorkingThread {
  269.         /**
  270.          * should we continue threating the queue ?
  271.          */
  272.         private volatile boolean timeout = false;
  273.         /**
  274.          * the real thread. note that it will be used as the lock-key only
  275.          * because its lifetime is the same as the Executor's one and it is not
  276.          * publicly visible (so no one can interfere with the notification
  277.          * system).
  278.          */
  279.         private final Thread thread;
  280.         private Task currentTask = null;
  281.         private WorkingThread() {
  282.             thread = new Thread(new Runnable() {
  283.                 public void run() {
  284.                     incrementThreadnumber();
  285.                     while (!timeout) {
  286.                         Task task = getTask();
  287.                         if (task == null)
  288.                             waitForNotification();
  289.                         else if (!executingTasks.contains(task))
  290.                             executeTask(task);
  291.                         else
  292.                             System.out.println("task :" + task
  293.                                     + "already running" );
  294.                     }
  295.                     decrementThreadnumber();
  296.                     System.out.println("working threads : " + threadNumber);
  297.                 }
  298.                 private synchronized void waitForNotification() {
  299.                     try {
  300.                         synchronized (thread) {
  301.                             thread.wait();
  302.                         }
  303.                     } catch (InterruptedException e) {
  304.                         //continue
  305.                     }
  306.                 }
  307.             });
  308.             thread.setName("network " + threadNumber);
  309.             thread.setDaemon(true);
  310.             thread.start();
  311.             System.out.println("working threads : " + threadNumber);
  312.         }
  313.         /**
  314.          * @return
  315.          */
  316.         public Task getCurrentTask() {
  317.             return currentTask;
  318.         }
  319.         /**
  320.          * tells this executor it took too long to complete.
  321.          *   
  322.          */
  323.         public void timeout() {
  324.             timeout = true;
  325.         }
  326.         /**
  327.          * called to alert that a new message entered the queue.
  328.          */
  329.         public void alertNewMessage() {
  330.             synchronized (thread) {
  331.                 thread.notify();
  332.             }
  333.         }
  334.         /**
  335.          * Executes the given task.
  336.          */
  337.         private void executeTask(final Task task) {
  338.             currentTask = task;
  339.             synchronized (NetworkScheduler.this) {
  340.                 startTask(task, this);
  341.                 executingTasks.add(task);
  342.             }
  343.             try {
  344.                 task.work();
  345.             } catch (Exception e) {
  346.                 task.onException(e);
  347.             } finally {
  348.                 synchronized (NetworkScheduler.this) {
  349.                     executingTasks.remove(task);
  350.                     endTask(task, this);
  351.                 }
  352.                 currentTask = null;
  353.             }
  354.         }
  355.     }
  356. }


 
c'est nul, il a gagné 67 lignes et pas une seule fonctionnalité.
 
edit : et puis c'est tout nul, à part l'idée de pas soucalsser Thread et l'idée de pas exposerle mécanisme de wait/notify inutilement, le reste est nul (sortir le timeout par ex. ou le faux observateur).


Message édité par nraynaud le 31-07-2004 à 00:38:11

---------------
trainoo.com, c'est fini
n°811715
Cherrytree
cn=?
Posté le 31-07-2004 à 08:54:21  profilanswer
 

J'avoue que je suis un poil dubitatif, là. J'lirais ça quand j'aurai décuvé.


---------------
Le site de ma maman
n°812235
darklord
You're welcome
Posté le 01-08-2004 à 11:47:27  profilanswer
 

ouais ouais c'est nul, t'as raison :o
 
:pfff:


---------------
Just because you feel good does not make you right
mood
Publicité
Posté le 01-08-2004 à 11:47:27  profilanswer
 

n°812250
nraynaud
lol
Posté le 01-08-2004 à 12:28:13  profilanswer
 

Code :
  1. /*
  2. * Created on 23 avr. 2004
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Library General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. * Library General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Library General Public
  14. * License along with this library; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 02111-1307, USA.
  17. */
  18. package jcoincoin.net;
  19. import java.util.HashMap;
  20. import java.util.HashSet;
  21. import java.util.LinkedList;
  22. import java.util.Map;
  23. import java.util.NoSuchElementException;
  24. import java.util.Set;
  25. import java.util.Timer;
  26. import java.util.TimerTask;
  27. /**
  28. * @author nraynaud
  29. *  
  30. * Represents a very simple time slicer. Using this avoid having lots of threads
  31. * in the system using the network randomly.
  32. *  
  33. * Units of work are represented by the Task interface. If the work takes more
  34. * than a certain amouth of time to complete, a second Thread is created to
  35. * continue fetching work out of the queue.
  36. *   
  37. */
  38. public class NetworkScheduler {
  39.     /**
  40.      * the time a task can run before we start a second thread to process the
  41.      * queue.
  42.      */
  43.     private static final int MAX_EXECUTION_TIME = 5000;
  44.     /**
  45.      * the great task queue
  46.      */
  47.     private LinkedList taskQueue = new LinkedList();
  48.     /**
  49.      * the big timer used for periodicity.
  50.      */
  51.     private Timer timer = null;
  52.     /**
  53.      * the hashmap Task -> PeriodicTask of the curently registered periodic
  54.      * tasks.
  55.      */
  56.     private final Map periodicTasksMap = new HashMap();
  57.     /**
  58.      * number of threads to process the task queue.
  59.      */
  60.     static private volatile int threadNumber = 0;
  61.     static private synchronized void incrementThreadnumber() {
  62.         threadNumber++;
  63.     }
  64.     static private synchronized void decrementThreadnumber() {
  65.         threadNumber--;
  66.     }
  67.     private Set executingTasks = new HashSet();
  68.     /**
  69.      * current main executor.
  70.      */
  71.     private Executor currentExecutor;
  72.     /**
  73.      * the big one scheduler
  74.      */
  75.     private static NetworkScheduler instance = null;
  76.     public static synchronized NetworkScheduler getInstance() {
  77.         if (instance == null)
  78.             instance = new NetworkScheduler();
  79.         return instance;
  80.     }
  81.     private NetworkScheduler() {
  82.     }
  83.     private void alertExecutor() {
  84.         assert (Thread.holdsLock(this));
  85.         getCurrentExecutor().alertNewMessage();
  86.     }
  87.     /**
  88.      *  
  89.      * @return the current executor, creating a new one if there is none.
  90.      */
  91.     private synchronized Executor getCurrentExecutor() {
  92.         if (currentExecutor == null)
  93.             currentExecutor = new Executor();
  94.         return currentExecutor;
  95.     }
  96.    
  97.     private synchronized void setCurrentExecutor(Executor ex) {
  98.         currentExecutor = ex;
  99.     }
  100.     private synchronized void timeoutCurrentExecutor() {
  101.         System.out.println("notice : task timeout : "
  102.                 + String.valueOf(getCurrentExecutor().getCurrentTask()));
  103.         getCurrentExecutor().timeout();
  104.         setCurrentExecutor(new Executor());
  105.     }
  106.     private synchronized Task getTask() {
  107.         try {
  108.             return (Task) taskQueue.removeFirst();
  109.         } catch (NoSuchElementException e) {
  110.             return null;
  111.         }
  112.     }
  113.     /**
  114.      * Immediately enqueue the given task for execution.
  115.      *  
  116.      * @param task
  117.      *            the task to enqueue.
  118.      */
  119.     public synchronized void enqueue(Task task) {
  120.         taskQueue.addLast(task);
  121.         alertExecutor();
  122.     }
  123.     /**
  124.      * Enqueue th task to be executed exactly at the end of the currently
  125.      * executing task. This means that unfair enqueuing are unfair betwen
  126.      * themselves too, this is not a priority scheme.
  127.      *  
  128.      * @param task
  129.      *            the work
  130.      */
  131.     public synchronized void unfairlyEnqueue(Task task) {
  132.         taskQueue.addFirst(task);
  133.         alertExecutor();
  134.     }
  135.     /**
  136.      * Schedules the given task to be enqueued regulary at the given period.
  137.      * Exactly, the task is sceduled to be reenqueued period millisecond after
  138.      * the end of it's execution. The task is first immediately enqueued.
  139.      *  
  140.      * @param task
  141.      *            the work unit.
  142.      * @param period
  143.      *            the period in milliseconds.
  144.      */
  145.     synchronized public void periodicalyEnqueue(final Task task,
  146.             final long period) {
  147.         PeriodicTask pTask = new PeriodicTask(task, period);
  148.         periodicTasksMap.put(task, pTask);
  149.         enqueue(pTask);
  150.     }
  151.     synchronized public void changePeriod(Task task, final long newPeriod) {
  152.         PeriodicTask pTask = (PeriodicTask) periodicTasksMap.get(task);
  153.         if (pTask == null)
  154.             throw new IllegalArgumentException(
  155.                     "the given task is not in the system" );
  156.         else
  157.             pTask.setPeriod(newPeriod);
  158.     }
  159.     synchronized public void removePeriodicTask(Task task) {
  160.         if (periodicTasksMap.remove(task) == null)
  161.             throw new IllegalArgumentException(
  162.                     "the given task is not in the system" );
  163.     }
  164.     /**
  165.      * Enqueues the given task after the given period.
  166.      *  
  167.      * @param task
  168.      *            the task to reenqueue
  169.      * @param delay
  170.      *            the delay to wait in milliseconds.
  171.      */
  172.     private void enqueueDelayed(final Task task, final long delay) {
  173.         getTimer().schedule(new TimerTask() {
  174.             public void run() {
  175.                 enqueue(task);
  176.             }
  177.         }, delay);
  178.     }
  179.     private synchronized Timer getTimer() {
  180.         if (timer == null)
  181.             timer = new Timer(true);
  182.         return timer;
  183.     }
  184.     /**
  185.      * Periodic Task proxy.
  186.      *  
  187.      * @author nraynaud
  188.      *   
  189.      */
  190.     private class PeriodicTask implements Task {
  191.         private final Task task;
  192.         volatile private long period;
  193.         /**
  194.          * @param task
  195.          * @param period
  196.          */
  197.         public PeriodicTask(final Task task, long period) {
  198.             this.task = task;
  199.             this.period = period;
  200.         }
  201.         public void work() {
  202.             try {
  203.                 task.work();
  204.             } finally {
  205.                 synchronized (NetworkScheduler.this) {
  206.                     if (periodicTasksMap.get(task) == this)
  207.                         enqueueDelayed(this, period);
  208.                 }
  209.             }
  210.         }
  211.         public String toString() {
  212.             return task.toString() + " (made periodic)";
  213.         }
  214.         public void onException(Exception e) {
  215.             task.onException(e);
  216.         }
  217.         public boolean equals(Object other) {
  218.             return task.equals(other);
  219.         }
  220.         public int hashCode() {
  221.             return task.hashCode();
  222.         }
  223.         /**
  224.          * @return Returns the period.
  225.          */
  226.         synchronized public long getPeriod() {
  227.             return period;
  228.         }
  229.         /**
  230.          * @param period
  231.          *            The period to set.
  232.          */
  233.         synchronized public void setPeriod(long period) {
  234.             this.period = period;
  235.         }
  236.     }
  237.     /**
  238.      * @author nraynaud
  239.      *  
  240.      * The executor is responsible for fetching tasks and executing them. If it
  241.      * as been timeouted, it will die after finishig the current task.
  242.      */
  243.     private final class Executor {
  244.         /**
  245.          * should we continue threating the queue ?
  246.          */
  247.         private volatile boolean timeout = false;
  248.         /**
  249.          * the real thread. note that it will be used as the lock-key only
  250.          * because its lifetime is the same as the Executor's one and it is not
  251.          * publicly visible (so no one can interfere with the notification
  252.          * system).
  253.          */
  254.         private final Thread thread;
  255.         private Task currentTask = null;
  256.         private Executor() {
  257.             thread = new Thread(new Runnable() {
  258.                 public void run() {
  259.                     incrementThreadnumber();
  260.                     while (!timeout) {
  261.                         Task task = getTask();
  262.                         if (task == null)
  263.                             waitForNotification();
  264.                         else if (!executingTasks.contains(task))
  265.                             executeTask(task);
  266.                         else
  267.                             System.out.println("task :" + task
  268.                                     + "already running" );
  269.                     }
  270.                     decrementThreadnumber();
  271.                     System.out.println("working threads : " + threadNumber);
  272.                 }
  273.                 private synchronized void waitForNotification() {
  274.                     try {
  275.                         synchronized (thread) {
  276.                             thread.wait();
  277.                         }
  278.                     } catch (InterruptedException e) {
  279.                         //continue
  280.                     }
  281.                 }
  282.             });
  283.             thread.setName("network " + threadNumber);
  284.             thread.setDaemon(true);
  285.             thread.start();
  286.             System.out.println("working threads : " + threadNumber);
  287.         }
  288.         /**
  289.          * @return
  290.          */
  291.         public Task getCurrentTask() {
  292.             return currentTask;
  293.         }
  294.         /**
  295.          * tells this executor it took too long to complete.
  296.          *   
  297.          */
  298.         public void timeout() {
  299.             timeout = true;
  300.         }
  301.         /**
  302.          * called to alert that a new message entered the queue.
  303.          */
  304.         public void alertNewMessage() {
  305.             synchronized (thread) {
  306.                 thread.notify();
  307.             }
  308.         }
  309.         /**
  310.          * Executes the given task.
  311.          */
  312.         private void executeTask(final Task task) {
  313.             currentTask = task;
  314.             assert (this == getCurrentExecutor());
  315.             TimerTask timeoutTask = new TimerTask() {
  316.                 public void run() {
  317.                     timeoutCurrentExecutor();
  318.                 }
  319.             };
  320.             getTimer().schedule(timeoutTask, MAX_EXECUTION_TIME);
  321.             synchronized (NetworkScheduler.this) {
  322.                 executingTasks.add(task);
  323.             }
  324.             try {
  325.                 task.work();
  326.             } catch (Exception e) {
  327.                 task.onException(e);
  328.             } finally {
  329.                 synchronized (NetworkScheduler.this) {
  330.                     executingTasks.remove(task);
  331.                 }
  332.                 timeoutTask.cancel();
  333.                 currentTask = null;
  334.             }
  335.         }
  336.     }
  337. }


 
bwalé, c'est la dernière.
 
En fait je finasse là-dessus parce que j'ai la flemme de m'attaquer à mon vrai pb avec cette appli : la configuration.


---------------
trainoo.com, c'est fini
n°812256
darklord
You're welcome
Posté le 01-08-2004 à 12:35:08  profilanswer
 

tain mais qu'est ce qui fout joce là [:wam]


Message édité par darklord le 01-08-2004 à 17:37:17

---------------
Just because you feel good does not make you right
n°812350
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 01-08-2004 à 17:37:27  profilanswer
 

space ce truc...
je viens de cliquer sur le lien "éditer le message" de nraynaud, puis j'ai fait retour sur la page précédente, et c'est redevenu normal :??:


---------------
J'ai un string dans l'array (Paris Hilton)
n°812351
nraynaud
lol
Posté le 01-08-2004 à 17:44:16  profilanswer
 

Harko > fait un simple "reload" de la page, ça suffit.


---------------
trainoo.com, c'est fini
n°812352
nraynaud
lol
Posté le 01-08-2004 à 17:45:06  profilanswer
 

et puis vas pas m'introduire des saloperies d'assembleux dans mon chef d'oeuvre /o\


---------------
trainoo.com, c'est fini
mood
Publicité
Posté le   profilanswer
 

 Page :   1  2
Page Suivante

Aller à :
Ajouter une réponse
 

Sujets relatifs
récupération du login windows en JAVA SCRIPTJAVA 3D
[JAVA] package ... does not exist[Java][Swing] Layout avec component centré non maximisé
[java] peut on gérer des fichiers excel ?Parser une structure XML en Java
probleme JAVA (applet)[divers] En votre âme, et consience, vous croyez que java a un avenir?
[Servlet Java] [Php] [Socket] Circulation des données Java <-> Php[java] tester si un fichier existe
Plus de sujets relatifs à : [Java] Multithreading et gestion des exceptions


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR