cleanStreamVariable(owner, variableName);
}
} catch (Exception e) {
- synchronized (session) {
+ session.getLock().lock();
+ try {
handleChangeVariablesError(session, (Component) owner, e,
new HashMap<String, Object>());
+ } finally {
+ session.getLock().unlock();
}
}
sendUploadResponse(request, response);
cleanStreamVariable(owner, variableName);
}
} catch (Exception e) {
- synchronized (session) {
+ session.getLock().lock();
+ try {
handleChangeVariablesError(session, (Component) owner, e,
new HashMap<String, Object>());
+ } finally {
+ session.getLock().unlock();
}
}
sendUploadResponse(request, response);
filename, type, contentLength);
try {
boolean listenProgress;
- synchronized (session) {
+ session.getLock().lock();
+ try {
streamVariable.streamingStarted(startedEvent);
out = streamVariable.getOutputStream();
listenProgress = streamVariable.listenProgress();
+ } finally {
+ session.getLock().unlock();
}
// Gets the output target stream
if (listenProgress) {
// update progress if listener set and contentLength
// received
- synchronized (session) {
+ session.getLock().lock();
+ try {
StreamingProgressEventImpl progressEvent = new StreamingProgressEventImpl(
filename, type, contentLength, totalBytes);
streamVariable.onProgress(progressEvent);
+ } finally {
+ session.getLock().unlock();
}
}
if (streamVariable.isInterrupted()) {
out.close();
StreamingEndEvent event = new StreamingEndEventImpl(filename, type,
totalBytes);
- synchronized (session) {
+ session.getLock().lock();
+ try {
streamVariable.streamingFinished(event);
+ } finally {
+ session.getLock().unlock();
}
} catch (UploadInterruptedException e) {
tryToCloseStream(out);
StreamingErrorEvent event = new StreamingErrorEventImpl(filename,
type, contentLength, totalBytes, e);
- synchronized (session) {
+ session.getLock().lock();
+ try {
streamVariable.streamingFailed(event);
+ } finally {
+ session.getLock().unlock();
}
// Note, we are not throwing interrupted exception forward as it is
// not a terminal level error like all other exception.
} catch (final Exception e) {
tryToCloseStream(out);
- synchronized (session) {
+ session.getLock().lock();
+ try {
StreamingErrorEvent event = new StreamingErrorEventImpl(
filename, type, contentLength, totalBytes, e);
streamVariable.streamingFailed(event);
// throw exception for terminal to be handled (to be passed to
// terminalErrorHandler)
throw new UploadException(e);
+ } finally {
+ session.getLock().unlock();
}
}
return startedEvent.isDisposed();
// The rest of the process is synchronized with the session
// in order to guarantee that no parallel variable handling is
// made
- synchronized (session) {
+ session.getLock().lock();
+ try {
// Finds the UI within the session
if (session.isRunning()) {
paintAfterVariableChanges(request, response, callback, repaintAll,
outWriter, uI, analyzeLayouts);
postPaint(uI);
+ } finally {
+ session.getLock().unlock();
}
outWriter.close();
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
import javax.portlet.PortletSession;
.findMethod(BootstrapListener.class, "modifyBootstrapPage",
BootstrapPageResponse.class);
+ private final Lock lock = new ReentrantLock();
+
/**
* An event sent to {@link #start(SessionStartEvent)} when a new Application
* is being started.
return uI;
}
Integer uiId = getUIId(request);
-
- synchronized (this) {
+ getLock().lock();
+ try {
uI = uIs.get(uiId);
if (uI == null) {
uI = findExistingUi(request);
}
- } // end synchronized block
+ } finally {
+ getLock().unlock();
+ }
UI.setCurrent(uI);
return Collections.unmodifiableCollection(uiProviders);
}
+ /**
+ * Gets the lock that should be used to synchronize usage of data inside
+ * this session.
+ *
+ * @return the lock that should be used for synchronization
+ */
+ public Lock getLock() {
+ return lock;
+ }
+
}
private class MassInsert extends Thread {
@Override
- public synchronized void start() {
- proggress.setVisible(true);
- proggress.setValue(new Float(0));
- proggress.setPollingInterval(100);
- process.setEnabled(false);
- proggress.setCaption("");
- super.start();
+ public void start() {
+ getContext().getLock().lock();
+ try {
+ proggress.setVisible(true);
+ proggress.setValue(new Float(0));
+ proggress.setPollingInterval(100);
+ process.setEnabled(false);
+ proggress.setCaption("");
+ super.start();
+ } finally {
+ getContext().getLock().unlock();
+ }
}
@Override
getRandonName());
}
c.commit();
- synchronized (MassInsertMemoryLeakTestApp.this) {
+ getContext().getLock().lock();
+ try {
proggress
.setValue(new Float((1.0f * cent) / cents));
proggress.setCaption("" + 100 * cent
+ " rows inserted");
+ } finally {
+ getContext().getLock().unlock();
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
- synchronized (MassInsertMemoryLeakTestApp.this) {
+ getContext().getLock().lock();
+ try {
proggress.setVisible(false);
proggress.setPollingInterval(0);
process.setEnabled(true);
+ } finally {
+ getContext().getLock().unlock();
}
}
}