[Libreoffice-commits] core.git: jurt/com
Noel Grandin
noel at peralex.com
Thu Jun 2 07:13:31 UTC 2016
jurt/com/sun/star/lib/uno/environments/remote/Job.java | 2
jurt/com/sun/star/lib/uno/environments/remote/JobQueue.java | 58 ++++--------
2 files changed, 24 insertions(+), 36 deletions(-)
New commits:
commit 3e4fad756a451eca546eb4b2cf481172c523c71a
Author: Noel Grandin <noel at peralex.com>
Date: Wed Jun 1 15:15:02 2016 +0200
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 at redhat.com>
Tested-by: Stephan Bergmann <sbergman at redhat.com>
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 9dc2052..f65ffff 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 a4dc753..131f2b5 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;
More information about the Libreoffice-commits
mailing list