Is adding routes thread safe in Spark framework?

SimpleRouteMatcher stores the added routes in an ArrayList.

public SimpleRouteMatcher() {
    routes = new ArrayList<RouteEntry>();
}

      

There seems to be no synchronization involved with accessing these routes. Since they are accessible from a separate stream of servers, are there any updates to the list of routes that might be visible?

+3


source to share


1 answer


You yourself answered the question - it looks like it's not . There was probably an assumption: adding routes will only happen on the main thread when the application starts, from the main method, so this can be implemented without streaming as intended.

If you need to safely modify routes from multiple threads, you can create wrapper methods for these operations, which synchronized

.



In my opinion, this operation should have been thread safe out of the box.

+1


source







All Articles