summaryrefslogtreecommitdiff
path: root/jurt/com/sun
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-06-01 15:15:02 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-06-02 07:12:57 +0000
commit3e4fad756a451eca546eb4b2cf481172c523c71a (patch)
tree9fecbbc7fe185b8afcbb030301cd688f51947e80 /jurt/com/sun
parent59fe25a4240b6b456456779b63694de18827d6f7 (diff)
Use ArrayList for JobQueue
and make various internals of the class privatey (This is not an ABI change, as package com.sun.star.lib.uno.environments.remote is not considered part of the stable URE interface; it is not included in the documentation at <http://api.libreoffice.org/docs/java/ref/index.html>.) Change-Id: I25719239c0208b770ecd96b452b4220ac02b309d Reviewed-on: https://gerrit.libreoffice.org/25779 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'jurt/com/sun')
-rw-r--r--jurt/com/sun/star/lib/uno/environments/remote/Job.java2
-rw-r--r--jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java58
2 files changed, 24 insertions, 36 deletions
diff --git a/jurt/com/sun/star/lib/uno/environments/remote/Job.java b/jurt/com/sun/star/lib/uno/environments/remote/Job.java
index 9dc20521fff7..f65ffff98ff0 100644
--- a/jurt/com/sun/star/lib/uno/environments/remote/Job.java
+++ b/jurt/com/sun/star/lib/uno/environments/remote/Job.java
@@ -41,8 +41,6 @@ import com.sun.star.uno.XCurrentContext;
* @since UDK1.0
*/
public class Job {
- protected Job _next;
-
protected IReceiver _iReceiver;
protected Message _iMessage;
Object _disposeId;
diff --git a/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java b/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java
index a4dc753a8e41..131f2b5cc56c 100644
--- a/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java
+++ b/jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java
@@ -19,6 +19,8 @@
package com.sun.star.lib.uno.environments.remote;
+import java.util.ArrayList;
+
import com.sun.star.lang.DisposedException;
/**
@@ -27,7 +29,7 @@ import com.sun.star.lang.DisposedException;
* <p>For every jobs thread id exists a job queue which is registered
* at the <code>ThreadPool</code>.</p>
*
- * <p>A JobQueue is splitted in a sync job queue and an async job queue.
+ * <p>A JobQueue is split into a sync job queue and an async job queue.
* The sync job queue is the registered queue, it delegates async jobs
* (put by <code>putjob</code>) into the async queue, which is only
* known by the sync queue.</p>
@@ -43,25 +45,24 @@ public class JobQueue {
*/
private static final boolean DEBUG = false;
- protected Job _head; // the head of the job list
- protected Job _tail; // the tail of the job list
+ final ArrayList<Job> jobList = new ArrayList<Job>();
- protected ThreadId _threadId; // the thread id of the queue
- protected int _ref_count = 0; // the stack deepness
- protected boolean _createThread; // create a worker thread, if needed
- protected boolean _createThread_now; // create a worker thread, if needed
- protected Thread _worker_thread; // the thread that does the jobs
+ private ThreadId _threadId; // the thread id of the queue
+ protected int _ref_count = 0; // the stack deepness
+ private boolean _createThread; // create a worker thread, if needed
+ private boolean _createThread_now; // create a worker thread, if needed
+ private Thread _worker_thread; // the thread that does the jobs
- protected Object _disposeId; // the active dispose id
- protected Object _doDispose = null;
- protected Throwable _throwable;
+ private Object _disposeId; // the active dispose id
+ private Object _doDispose = null;
+ private Throwable _throwable;
- protected JobQueue _async_jobQueue; // chaining job queues for asyncs
+ JobQueue _async_jobQueue; // chaining job queues for asyncs
protected JobQueue _sync_jobQueue; // chaining job queues for syncs
- protected boolean _active = false;
+ private boolean _active = false;
- protected JavaThreadPoolFactory _javaThreadPoolFactory;
+ private JavaThreadPoolFactory _javaThreadPoolFactory;
/**
* A thread for dispatching jobs.
@@ -88,7 +89,7 @@ public class JobQueue {
try {
enter(2000, _disposeId);
} catch(Throwable throwable) {
- if(_head != null || _active) { // there was a job in progress, so give a stack
+ if(!jobList.isEmpty() || _active) { // there was a job in progress, so give a stack
System.err.println(getClass().getName() + " - exception occurred:" + throwable);
throwable.printStackTrace(System.err);
}
@@ -186,13 +187,13 @@ public class JobQueue {
* @return a job or null if timed out.
*/
private Job removeJob(int waitTime) {
- if(DEBUG) System.err.println("##### " + getClass().getName() + ".removeJob:" + _head + " " + _threadId);
+ if(DEBUG) System.err.println("##### " + getClass().getName() + ".removeJob:" + jobList + " " + _threadId);
Job job = null;
synchronized (this) {
// wait max. waitTime time for a job to enter the queue
boolean waited = false;
- while(_head == null && (waitTime == 0 || !waited)) {
+ while(jobList.isEmpty() && (waitTime == 0 || !waited)) {
if(_doDispose == _disposeId) {
_doDispose = null;
throw (DisposedException)
@@ -214,14 +215,8 @@ public class JobQueue {
}
- if(_head != null) {
- Job current = _head;
- _head = _head._next;
-
- if(_head == null)
- _tail = null;
-
- job = current;
+ if(!jobList.isEmpty()) {
+ job = jobList.remove(0);
_active = true;
}
}
@@ -230,8 +225,8 @@ public class JobQueue {
if(job != null && _async_jobQueue != null) {
synchronized(_async_jobQueue) {
// wait for async queue to be empty and last job to be done
- while(_async_jobQueue._active || _async_jobQueue._head != null) {
- if(DEBUG) System.err.println("waiting for async:" + _async_jobQueue._head + " " + _async_jobQueue._worker_thread);
+ while(_async_jobQueue._active || !_async_jobQueue.jobList.isEmpty()) {
+ if(DEBUG) System.err.println("waiting for async:" + _async_jobQueue.jobList + " " + _async_jobQueue._worker_thread);
if(_doDispose == _disposeId) {
_doDispose = null;
@@ -260,12 +255,7 @@ public class JobQueue {
synchronized void putJob(Job job, Object disposeId) {
if(DEBUG) System.err.println("##### " + getClass().getName() + ".putJob todoes: " + " job:" + job);
- if(_tail != null)
- _tail._next = job;
- else
- _head = job;
-
- _tail = job;
+ jobList.add(job);
if(_worker_thread == null && _createThread && _createThread_now) { // if there is no thread, which dispatches and if shall create one, create one
@@ -340,7 +330,7 @@ public class JobQueue {
if(DEBUG) System.err.println("##### " + getClass().getName() + ".enter leaving: " + _threadId + " " + _worker_thread + " " + hold_worker_thread + " " + result);
synchronized(this) {
- if(job != null || (quit && _head == null)) {
+ if(job != null || (quit && jobList.isEmpty())) {
_worker_thread = hold_worker_thread;
_createThread_now = true;