Search in sources :

Example 96 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project tomcat by apache.

the class WebappClassLoaderBase method loadedByThisOrChild.

/**
 * @param o object to test, may be null
 * @return <code>true</code> if o has been loaded by the current classloader
 * or one of its descendants.
 */
private boolean loadedByThisOrChild(Object o) {
    if (o == null) {
        return false;
    }
    Class<?> clazz;
    if (o instanceof Class) {
        clazz = (Class<?>) o;
    } else {
        clazz = o.getClass();
    }
    ClassLoader cl = clazz.getClassLoader();
    while (cl != null) {
        if (cl == this) {
            return true;
        }
        cl = cl.getParent();
    }
    if (o instanceof Collection<?>) {
        Iterator<?> iter = ((Collection<?>) o).iterator();
        try {
            while (iter.hasNext()) {
                Object entry = iter.next();
                if (loadedByThisOrChild(entry)) {
                    return true;
                }
            }
        } catch (ConcurrentModificationException e) {
            log.warn(sm.getString("webappClassLoader.loadedByThisOrChildFail", clazz.getName(), getContextName()), e);
        }
    }
    return false;
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) URLClassLoader(java.net.URLClassLoader) InstrumentableClassLoader(org.apache.tomcat.InstrumentableClassLoader) Collection(java.util.Collection) PermissionCollection(java.security.PermissionCollection)

Example 97 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project cpsolver by UniTime.

the class SwapStudentSelection method selectNeighbour.

/**
 * For each student that does not have a complete schedule, try to find a
 * request and a student that can be moved out of an enrollment so that the
 * selected student can be assigned to the selected request.
 */
@Override
public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
    Student student = null;
    while ((student = nextStudent()) != null) {
        Progress p = Progress.getInstance(solution.getModel());
        p.incProgress();
        if (p.getProgress() > 2.0 * p.getProgressMax())
            return null;
        if (student.isComplete(solution.getAssignment()) || student.nrAssignedRequests(solution.getAssignment()) == 0)
            continue;
        for (int i = 0; i < 5; i++) {
            try {
                Selection selection = getSelection(solution.getAssignment(), student);
                Neighbour<Request, Enrollment> neighbour = selection.select();
                if (neighbour != null) {
                    addStudent(student);
                    return neighbour;
                } else
                    iProblemStudents.addAll(selection.getProblemStudents());
                break;
            } catch (ConcurrentModificationException e) {
            }
        }
    }
    return null;
}
Also used : Progress(org.cpsolver.ifs.util.Progress) ConcurrentModificationException(java.util.ConcurrentModificationException) NeighbourSelection(org.cpsolver.ifs.heuristics.NeighbourSelection) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student)

Example 98 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project cpsolver by UniTime.

the class BacktrackSelection method selectNeighbour.

@Override
public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
    Request request = null;
    if (iNbrIterations > iMaxIterations)
        return null;
    while ((request = nextRequest()) != null) {
        Progress.getInstance(solution.getModel()).incProgress();
        Enrollment e = request.getAssignment(solution.getAssignment());
        if (e != null && request instanceof FreeTimeRequest)
            continue;
        if (e != null && e.getPriority() == 0 && ((CourseRequest) request).getSelectedChoices().isEmpty())
            continue;
        for (int i = 0; i < 5; i++) {
            try {
                Neighbour<Request, Enrollment> n = iRBtNSel.selectNeighbour(solution, request);
                if (iRBtNSel.getContext() != null) {
                    iNbrIterations++;
                    iTotalTime += iRBtNSel.getContext().getTime();
                    if (iRBtNSel.getContext().isTimeoutReached())
                        iNbrTimeoutReached++;
                    if (n == null)
                        iNbrNoSolution++;
                }
                if (n != null && n.value(solution.getAssignment()) <= 0.0)
                    return n;
                break;
            } catch (ConcurrentModificationException ex) {
            }
        }
    }
    return null;
}
Also used : FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) ConcurrentModificationException(java.util.ConcurrentModificationException) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 99 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project ignite by apache.

the class CacheExchangeMergeTest method testNoConcurrentModificationExceptionAfterMergeExchanges.

/**
 * Test checks that there will be no {@link ConcurrentModificationException}
 * when merging exchanges and iterating over {@link ExchangeDiscoveryEvents#events} at the same time.
 *
 * @throws Exception If failed.
 */
@Test
public void testNoConcurrentModificationExceptionAfterMergeExchanges() throws Exception {
    testSpi = true;
    LogListener logLsnr = matches("Merge exchange future on finish [").build();
    listeningLog.registerAllListeners(logLsnr);
    AtomicBoolean stop = new AtomicBoolean();
    Collection<Exception> exceptions = new ConcurrentLinkedQueue<>();
    try {
        startGrid(0);
        for (int i = 1; i < 9; i++) {
            IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(i));
            TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) cfg.getCommunicationSpi());
            spi.blockMessages((node, msg) -> delay(msg));
            runAsync(() -> startGrid(cfg), "create-node-" + cfg.getIgniteInstanceName());
            spi.waitForBlocked();
        }
        List<Ignite> allNodes = IgnitionEx.allGridsx();
        CountDownLatch latch = new CountDownLatch(allNodes.size());
        for (Ignite gridEx : allNodes) {
            runAsync(() -> {
                Collection<DiscoveryEvent> evts = ((IgniteEx) gridEx).context().cache().context().exchange().lastTopologyFuture().events().events();
                latch.countDown();
                int i = 0;
                while (!stop.get()) {
                    try {
                        for (DiscoveryEvent evt : evts) {
                            if (nonNull(evt))
                                i++;
                        }
                    } catch (ConcurrentModificationException e) {
                        exceptions.add(e);
                        log.error("i = " + i, e);
                        break;
                    }
                }
            }, "get-ex-" + gridEx.configuration().getIgniteInstanceName());
        }
        for (Ignite node : allNodes) TestRecordingCommunicationSpi.spi(node).stopBlock();
        latch.await();
        awaitPartitionMapExchange();
    } finally {
        stop.set(true);
    }
    assertTrue(logLsnr.check());
    assertTrue(exceptions.isEmpty());
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) LogListener(org.apache.ignite.testframework.LogListener) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentModificationException(java.util.ConcurrentModificationException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 100 with ConcurrentModificationException

use of java.util.ConcurrentModificationException in project jPOS by jpos.

the class ContextTest method testConcurrentException.

@Test
public void testConcurrentException() throws InterruptedException {
    final Context ctx = new Context();
    CountDownLatch latch = new CountDownLatch(1);
    AtomicInteger errorsPut = new AtomicInteger();
    AtomicInteger errorsDump = new AtomicInteger();
    Runnable addEvent = () -> {
        for (int i = 0; i < 10000; i++) {
            try {
                ctx.put("Prop-" + i, i);
            } catch (ConcurrentModificationException e) {
                errorsPut.incrementAndGet();
            }
            Thread.yield();
        }
        latch.countDown();
    };
    Runnable newFrozen = () -> {
        while (latch.getCount() > 0) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ctx.dumpMap(new PrintStream(baos), "");
            } catch (ConcurrentModificationException e) {
                errorsDump.incrementAndGet();
            }
            Thread.yield();
        }
    };
    new Thread(addEvent).start();
    Thread t1 = new Thread(newFrozen);
    t1.start();
    t1.join();
    if (errorsPut.get() + errorsDump.get() > 0)
        fail("Concurrent Exception has been raised " + errorsPut.get() + "/" + errorsDump.get() + " time(s)");
}
Also used : PrintStream(java.io.PrintStream) ConcurrentModificationException(java.util.ConcurrentModificationException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentModificationException (java.util.ConcurrentModificationException)206 Iterator (java.util.Iterator)34 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)24 HashSet (java.util.HashSet)23 Map (java.util.Map)19 Set (java.util.Set)19 Test (org.junit.Test)19 ResultSet (java.sql.ResultSet)16 HashMap (java.util.HashMap)13 NoSuchElementException (java.util.NoSuchElementException)13 List (java.util.List)10 Collection (java.util.Collection)9 GameLocal (org.apache.openejb.test.entity.cmr.manytomany.GameLocal)8 PlatformLocal (org.apache.openejb.test.entity.cmr.manytomany.PlatformLocal)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 AbstractList (java.util.AbstractList)6 LinkedList (java.util.LinkedList)6 ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)6 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)6