bump product version to 5.0.4.1
[LibreOffice.git] / jurt / com / sun / star / lib / uno / environments / remote / JavaThreadPoolFactory.java
blob9422742e1dc0abfa47f62d44efe2196e0c03f3c0
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com.sun.star.lib.uno.environments.remote;
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.WeakHashMap;
25 final class JavaThreadPoolFactory {
27 public IThreadPool createThreadPool() {
28 return new JavaThreadPool(this);
31 public void addJobQueue(JobQueue jobQueue) {
32 synchronized (jobQueues) {
33 jobQueues.put(jobQueue.getThreadId(), jobQueue);
37 public void removeJobQueue(JobQueue jobQueue) {
38 synchronized (jobQueues) {
39 jobQueues.remove(jobQueue.getThreadId());
43 public JobQueue getJobQueue(ThreadId threadId) {
44 synchronized (jobQueues) {
45 return jobQueues.get(threadId);
49 public JobQueue getAsyncJobQueue(ThreadId threadId) {
50 JobQueue q = getJobQueue(threadId);
51 return q == null ? null : q._async_jobQueue;
54 public void dispose(Object disposeId, Throwable throwable) {
55 JobQueue[] qs;
56 synchronized (jobQueues) {
57 Collection<JobQueue> c = jobQueues.values();
58 qs = c.toArray(new JobQueue[c.size()]);
60 for (int i = 0; i < qs.length; ++i) {
61 qs[i].dispose(disposeId, throwable);
65 public static ThreadId getThreadId() {
66 Thread t = Thread.currentThread();
67 if (t instanceof JobQueue.JobDispatcher) {
68 return ((JobQueue.JobDispatcher) t).getThreadId();
69 } else {
70 ThreadId id;
71 synchronized (threadIdMap) {
72 id = threadIdMap.get(t);
73 if (id == null) {
74 id = ThreadId.createFresh();
75 threadIdMap.put(t, id);
78 return id;
82 private static final WeakHashMap<Thread, ThreadId> threadIdMap = new WeakHashMap<Thread, ThreadId>();
83 private final HashMap<ThreadId, JobQueue> jobQueues = new HashMap<ThreadId, JobQueue>();