File tree Expand file tree Collapse file tree
src/main/java/org/javasim Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -152,18 +152,52 @@ static synchronized boolean schedule () throws SimulationException
152152
153153 try
154154 {
155+ /*
156+ * For some reason when executing tests in junit an old and dead
157+ * thread appears in the simulation queue. Have only ever seen this
158+ * be a single thread instance, but it is reproducible every time.
159+ *
160+ * https://github.com/nmcl/JavaSim/issues/64
161+ *
162+ * Will try to find out what actually causes this and remove the
163+ * workaround eventually.
164+ *
165+ * https://github.com/nmcl/JavaSim/issues/76
166+ */
167+
155168 SimulationProcess .Current = Scheduler .ReadyQueue .remove ();
169+ boolean done = true ;
156170
157- if ( SimulationProcess . Current . getThreadGroup () == null )
171+ do
158172 {
159- SimulationProcess .Current = Scheduler .ReadyQueue .remove ();
160- p = SimulationProcess .Current ;
173+ if (SimulationProcess .Current != null )
174+ {
175+ if (SimulationProcess .Current .getThreadGroup () == null )
176+ {
177+ SimulationProcess .Current = Scheduler .ReadyQueue .remove ();
178+ p = SimulationProcess .current ();
179+ done = false ;
180+ }
181+ else
182+ done = true ;
183+ }
184+ else
185+ throw new NoSuchElementException ();
161186 }
187+ while (!done );
162188 }
163189 catch (NoSuchElementException e )
164190 {
165191 System .out .println ("Simulation queue empty." );
192+
193+ return false ;
166194 }
195+ catch (NullPointerException e )
196+ {
197+ System .out .println ("Simulation queue empty." );
198+
199+ return false ;
200+ }
167201
168202 if (SimulationProcess .Current .evtime () < 0 )
169203 throw new SimulationException ("Invalid SimulationProcess wakeup time." );
You can’t perform that action at this time.
0 commit comments