concurrency - Java Fork Join Pool Timing Issue -


i'm trying implement fork join pool take children of 1 node , explore them concurrently. think fork join pool executes threads , shuts down quickly, causing threads stop executing?

so far have code:

main method:

    while (!(pqopen.isempty()))      {                tempvertex = pqopen.getnextitem();                 if (tempvertex.city == endlocation.city)           {             resetvertex();                        return tempvertex;                  }         else          {                                         forkjoinpool forkjoinpool = new forkjoinpool(tempvertex.neighbors.getnoofitems());             (int = 0; < tempvertex.neighbors.getnoofitems(); i++) //for each neighbor of tempvertex             {                 forkjoinpool.execute(new neighbourthread(tempvertex, allvertices, routetype, pqopen, i, endlocation));              }             forkjoinpool.shutdown();         }     }     return null; }    

this class runs:

public class neighbourthread extends recursiveaction {     vertex tempvertex, endlocation;     vertexhashmap allvertices;     int routetype, i;     priorityqueue pqopen;         public neighbourthread(vertex tempvertex, vertexhashmap allvertices, int routetype, priorityqueue pqopen, int i, vertex endlocation)     {         this.allvertices = allvertices;         this.routetype = routetype;         this.tempvertex = tempvertex;         this.pqopen = pqopen;          this.i = i;         this.endlocation = endlocation;     }      @override     public void compute() {           edge currentroad = tempvertex.neighbors.getitem(i);                                        vertex vertexneighbour = allvertices.getvalue(currentroad.toid);               if (vertexneighbour.inclosed)//               return null;               if ((!vertexneighbour.inopen) || temp_g_score < vertexneighbour.gettentativedistance())            {               vertexneighbour.from = tempvertex;               vertexneighbour.settentativedistance(temp_g_score);                                                  // if neighbor isn't in open set, add open set               if (!vertexneighbour.inopen)                {                   vertexneighbour.inopen = true;                   pqopen.additem(vertexneighbour);               }           }     } 

i've removed majority of code within compute() don't feel it's relevant problem.

i think problem forkjoinpool.shutdown() line gets executed before threads have been created have finished executing. there way ensure threads finished before loop round top of while loop?

i bet need awaittermination on forkjoinpool after shutting down. pool should accept , execute tasks while in shutdown phase won't accept new tasks

forkjoinpool.awaittermination(integer.max_value, timeunit.days);


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -