use of java.util.ConcurrentModificationException in project hadoop by apache.
the class TestLeafQueue method testConcurrentAccess.
@Test
public void testConcurrentAccess() throws Exception {
YarnConfiguration conf = new YarnConfiguration();
MockRM rm = new MockRM();
rm.init(conf);
rm.start();
final String queue = "default";
final String user = "user";
CapacityScheduler cs = (CapacityScheduler) rm.getResourceScheduler();
final LeafQueue defaultQueue = (LeafQueue) cs.getQueue(queue);
final List<FiCaSchedulerApp> listOfApps = createListOfApps(10000, user, defaultQueue);
final CyclicBarrier cb = new CyclicBarrier(2);
final List<ConcurrentModificationException> conException = new ArrayList<ConcurrentModificationException>();
Thread submitAndRemove = new Thread(new Runnable() {
@Override
public void run() {
for (FiCaSchedulerApp fiCaSchedulerApp : listOfApps) {
defaultQueue.submitApplicationAttempt(fiCaSchedulerApp, user);
}
try {
cb.await();
} catch (Exception e) {
// Ignore
}
for (FiCaSchedulerApp fiCaSchedulerApp : listOfApps) {
defaultQueue.finishApplicationAttempt(fiCaSchedulerApp, queue);
}
}
}, "SubmitAndRemoveApplicationAttempt Thread");
Thread getAppsInQueue = new Thread(new Runnable() {
List<ApplicationAttemptId> apps = new ArrayList<ApplicationAttemptId>();
@Override
public void run() {
try {
try {
cb.await();
} catch (Exception e) {
// Ignore
}
defaultQueue.collectSchedulerApplications(apps);
} catch (ConcurrentModificationException e) {
conException.add(e);
}
}
}, "GetAppsInQueue Thread");
submitAndRemove.start();
getAppsInQueue.start();
submitAndRemove.join();
getAppsInQueue.join();
assertTrue("ConcurrentModificationException is thrown", conException.isEmpty());
rm.stop();
}
use of java.util.ConcurrentModificationException in project morphia by mongodb.
the class DatastoreImpl method tryVersionedUpdate.
private <T> WriteResult tryVersionedUpdate(final DBCollection dbColl, final T entity, final DBObject dbObj, final Object idValue, final InsertOptions options, final MappedClass mc) {
WriteResult wr;
if (mc.getFieldsAnnotatedWith(Version.class).isEmpty()) {
return null;
}
final MappedField mfVersion = mc.getMappedVersionField();
final String versionKeyName = mfVersion.getNameToStore();
Long oldVersion = (Long) mfVersion.getFieldValue(entity);
long newVersion = nextValue(oldVersion);
dbObj.put(versionKeyName, newVersion);
if (idValue != null && newVersion != 1) {
final Query<?> query = find(dbColl.getName(), entity.getClass()).disableValidation().filter(Mapper.ID_KEY, idValue).enableValidation().filter(versionKeyName, oldVersion);
final UpdateResults res = update(query, dbObj, new UpdateOptions().bypassDocumentValidation(options.getBypassDocumentValidation()).writeConcern(options.getWriteConcern()));
wr = res.getWriteResult();
if (res.getUpdatedCount() != 1) {
throw new ConcurrentModificationException(format("Entity of class %s (id='%s',version='%d') was concurrently updated.", entity.getClass().getName(), idValue, oldVersion));
}
} else {
wr = saveDocument(dbColl, dbObj, options);
}
return wr;
}
use of java.util.ConcurrentModificationException in project hadoop by apache.
the class TestFileCreationEmpty method testLeaseExpireEmptyFiles.
/**
* This test creates three empty files and lets their leases expire.
* This triggers release of the leases.
* The empty files are supposed to be closed by that
* without causing ConcurrentModificationException.
*/
@Test
public void testLeaseExpireEmptyFiles() throws Exception {
final Thread.UncaughtExceptionHandler oldUEH = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
if (e instanceof ConcurrentModificationException) {
LeaseManager.LOG.error("t=" + t, e);
isConcurrentModificationException = true;
}
}
});
System.out.println("testLeaseExpireEmptyFiles start");
final long leasePeriod = 1000;
final int DATANODE_NUM = 3;
final Configuration conf = new HdfsConfiguration();
conf.setInt(DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 1000);
conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1);
// create cluster
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(DATANODE_NUM).build();
try {
cluster.waitActive();
DistributedFileSystem dfs = cluster.getFileSystem();
// create a new file.
TestFileCreation.createFile(dfs, new Path("/foo"), DATANODE_NUM);
TestFileCreation.createFile(dfs, new Path("/foo2"), DATANODE_NUM);
TestFileCreation.createFile(dfs, new Path("/foo3"), DATANODE_NUM);
// set the soft and hard limit to be 1 second so that the
// namenode triggers lease recovery
cluster.setLeasePeriod(leasePeriod, leasePeriod);
// wait for the lease to expire
try {
Thread.sleep(5 * leasePeriod);
} catch (InterruptedException e) {
}
assertFalse(isConcurrentModificationException);
} finally {
Thread.setDefaultUncaughtExceptionHandler(oldUEH);
cluster.shutdown();
}
}
use of java.util.ConcurrentModificationException in project pcgen by PCGen.
the class CharacterFacadeImpl method export.
/**
* @see pcgen.core.facade.CharacterFacade#export(pcgen.io.ExportHandler, java.io.BufferedWriter)
*/
@Override
public void export(ExportHandler theHandler, BufferedWriter buf) throws ExportException {
final int maxRetries = 3;
for (int i = 0; i < maxRetries; i++) {
try {
Logging.log(Logging.DEBUG, "Starting export at serial " + theCharacter.getSerial() + " to " + theHandler.getTemplateFile());
PlayerCharacter exportPc = getExportCharacter();
//PlayerCharacter exportPc = theCharacter;
theHandler.write(exportPc, buf);
Logging.log(Logging.DEBUG, "Finished export at serial " + theCharacter.getSerial() + " to " + theHandler.getTemplateFile());
return;
} catch (ConcurrentModificationException e) {
Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
for (Entry<Thread, StackTraceElement[]> threadEntry : allStackTraces.entrySet()) {
if (threadEntry.getValue().length > 1) {
StringBuilder sb = new StringBuilder("Thread: " + threadEntry.getKey() + "\n");
for (StackTraceElement elem : threadEntry.getValue()) {
sb.append(" ");
sb.append(elem.toString());
sb.append("\n");
}
Logging.log(Logging.INFO, sb.toString());
}
}
Logging.log(Logging.WARNING, "Retrying export after ConcurrentModificationException", e);
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
Logging.errorPrint("Interrupted sleep - probably closing.");
return;
}
}
}
Logging.errorPrint("Unable to export using " + theHandler.getTemplateFile() + " due to concurrent modifications.");
}
use of java.util.ConcurrentModificationException in project ACS by ACS-Community.
the class AcsCorba method shutdownORB.
/**
* Calls <code>m_orb.shutdown(wait_for_completion)</code>.
* <p>
* If this method is invoked from an ORB thread (as it happens in the Java container in case of shutdown being
* commanded by the manager), it returns immediately, independently of the <code>wait_for_completion</code>
* parameter. The <code>Orb#shutdown</code> call will then run asynchronously. Note that shutting down the ORB from
* within an ORB thread would result in a deadlock (or BAD_INV_ORDER exception) if <code>wait_for_completion</code>
* is true. The Java container will nonetheless wait for the ORB shutdown, because its main thread blocks on ORB#run
* and only continues when the ORB is shut down.
*
* @Todo: As a workaround for a JacORB bug (http://www.jacorb.org/cgi-bin/bugzilla/show_bug.cgi?id=537), we
* currently skim off the <code>ConcurrentModificationException</code> that the unsynchronized HashMap of
* <code>ClientConnectionManager.shutdown</code> may throw. This should be removed when we upgrade JacORB.
* @param wait_for_completion
* blocks this call until ORB has shut down. Will be effectively <code>false</code> if
* <code>isOrbThread == true</code>.
* @param isOrbThread
* must be <code>true</code> if the calling thread services a Corba invocation, e.g. to
* {@link AcsContainer#shutdown}.
* Note that JacORB has the proprietary method <code>isInInvocationContext</code>, but we need the explicit flag
* in order to stay ORB-independent.
*/
public void shutdownORB(final boolean wait_for_completion, boolean isOrbThread) {
if (m_orb != null) {
if (isOrbThread) {
Runnable cmd = new Runnable() {
public void run() {
try {
// since m_orb.shutdown runs asynchronously anyway, there is no advantage in passing
// wait_for_completion even if that flag is set to true.
m_orb.shutdown(false);
} catch (ConcurrentModificationException ex) {
// ignore, see javadoc
}
}
};
(new DaemonThreadFactory("ShutdownORB")).newThread(cmd).start();
} else {
// not an ORB thread, thus we can call shutdown directly
try {
if (wait_for_completion) {
// There appears to be a bug in JacORB that makes "orb.shutdown(true)" return too early (before shutdown completed),
// which then depending on timing can make a subsequent call to orb#destroy hang.
// Here we try out some additional synch'ing through Orb#run, and use a timeout to avoid blocking forever.
// However the premature return could be caused by the occasional ConcurrentModificationException (see comment on JacORB bug)
// in which case the additional orb shutdown synchronization on return from orb.run is useless.
// For ACS 8.0 we use both strategies though, the additional synch'ing and a sleep delay when catching ConcurrentModificationException.
final CountDownLatch synch1 = new CountDownLatch(1);
final CountDownLatch synch2 = new CountDownLatch(1);
Runnable cmd = new Runnable() {
public void run() {
synch1.countDown();
m_orb.run();
synch2.countDown();
}
};
// Start this ORB-blocking thread, and wait until it actually runs.
(new DaemonThreadFactory("WorkaroundBlockOnOrbTillShutdownCompletes")).newThread(cmd).start();
try {
synch1.await();
// sleep one second to minimize the risk that orb.run() has not made it to the point where it blocks
// when we call orb.shutdown next
Thread.sleep(1000);
} catch (InterruptedException ex1) {
// loggers probably don't work any more even though we have not called orb.shutdown yet,
// but the log manager and handlers has likely been flushed and shut down already
System.out.println("Failed to wait for the thread that should call orb.run to synch with ORB shutdown. " + ex1.toString());
}
// this call should only return when the ORB has shut down, but it may return too early
m_orb.shutdown(true);
// orb.shutdown(true) returned too soon.
try {
boolean orbRunUnblocked = synch2.await(30, TimeUnit.SECONDS);
if (!orbRunUnblocked) {
// Loggers cannot be expected to work at this point, thus printing to stdout
System.out.println("Failed to return within 30 s from orb.run() after ORB shutdown.");
}
} catch (InterruptedException ex) {
// Loggers cannot be expected to work at this point, thus printing to stdout
System.out.println("InterruptedException waiting for orb.run() to return after ORB shutdown. " + ex.toString());
}
} else {
// don't wait for orb shutdown to complete...
m_orb.shutdown(false);
}
} catch (ConcurrentModificationException ex) {
System.out.println("Caught a ConcurrentModificationException from ORB shutdown. " + "This should be harmless, see known JacORB bug http://www.jacorb.org/cgi-bin/bugzilla/show_bug.cgi?id=537");
if (wait_for_completion) {
// which the client could interpret to not call orb.destroy
try {
Thread.sleep(2000);
} catch (InterruptedException ex1) {
System.out.println("InterruptedException while sleeping after the ConcurrentModificationException in orb.shutdown");
}
}
}
}
}
}
Aggregations