#vulnerable code 
                                @Override
    public void rebalance(DispatcherThread dispatcherThread) {
        int load = dispatcherThread.getLoad();
        DispatcherThread minLoadThread = createNewThreadIfPossible();
        if ( minLoadThread != null ) {
            // split
            dispatcherThread.splitTo(minLoadThread);
            minLoadThread.start();
            return;
        }
        minLoadThread = findMinLoadThread(load / 4);
        if ( minLoadThread == null ) {
            // does not pay off. stay on current
//            System.out.println("no rebalance possible");
            return;
        }
        // move cheapest actor up to half load
        synchronized (dispatcherThread.queueList) {
            long minNanos = Long.MAX_VALUE;
            Actor minActor = null;
            for (int i = 0; i < dispatcherThread.queueList.size(); i++) {
                Actor actor = dispatcherThread.queueList.get(i);
                if (actor.__nanos < minNanos) {
                    minNanos = actor.__nanos;
                    minActor = actor;
                }
            }
            if (minActor != null) {
                //                System.out.println("move "+minActor+" from "+dispatcherThread+" to "+minLoadThread);
                dispatcherThread.removeActor(minActor);
                minLoadThread.addActor(minActor);
                dispatcherThread.applyQueueList();
            }
        }
    } 
                            #location 3 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                @Override
    public void rebalance(DispatcherThread dispatcherThread) {
        synchronized (balanceLock) {
            long load = dispatcherThread.getLoadNanos();
            DispatcherThread minLoadThread = createNewThreadIfPossible();
            if (minLoadThread != null) {
                // split
                dispatcherThread.splitTo(minLoadThread);
                minLoadThread.start();
                return;
            }
            minLoadThread = findMinLoadThread(2 * load / 3, null);
            if (minLoadThread == null || minLoadThread == dispatcherThread) {
                // does not pay off. stay on current
                //            System.out.println("no rebalance possible");
                return;
            }
            // move cheapest actor
            synchronized (dispatcherThread.queueList) {
                ArrayList<Actor> qList = new ArrayList<>(dispatcherThread.queueList);
                long otherLoad = minLoadThread.getLoadNanos();
                for (int i = 0; i < qList.size(); i++) {
                    Actor actor = qList.get(i);
                    if (otherLoad + actor.__nanos < load - actor.__nanos) {
                        otherLoad += actor.__nanos;
                        load -= actor.__nanos;
                        System.out.println("move for idle " + actor.__nanos + " myload " + load + " otherlOad " + otherLoad);
                        dispatcherThread.removeActor(actor);
                        minLoadThread.addActor(actor);
                        dispatcherThread.applyQueueList();
                    }
                }
            }
        }
    }