1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: JavaThreadPoolFactory.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com
.sun
.star
.lib
.uno
.environments
.remote
;
33 import java
.util
.Collection
;
34 import java
.util
.HashMap
;
35 import java
.util
.WeakHashMap
;
37 final class JavaThreadPoolFactory
{
38 public JavaThreadPoolFactory() {}
40 public IThreadPool
createThreadPool() {
41 return new JavaThreadPool(this);
44 public void addJobQueue(JobQueue jobQueue
) {
45 synchronized (jobQueues
) {
46 jobQueues
.put(jobQueue
.getThreadId(), jobQueue
);
50 public void removeJobQueue(JobQueue jobQueue
) {
51 synchronized (jobQueues
) {
52 jobQueues
.remove(jobQueue
.getThreadId());
56 public JobQueue
getJobQueue(ThreadId threadId
) {
57 synchronized (jobQueues
) {
58 return (JobQueue
) jobQueues
.get(threadId
);
62 public JobQueue
getAsyncJobQueue(ThreadId threadId
) {
63 JobQueue q
= getJobQueue(threadId
);
64 return q
== null ?
null : q
._async_jobQueue
;
67 public void dispose(Object disposeId
, Throwable throwable
) {
69 synchronized (jobQueues
) {
70 Collection c
= jobQueues
.values();
71 qs
= (JobQueue
[]) c
.toArray(new JobQueue
[c
.size()]);
73 for (int i
= 0; i
< qs
.length
; ++i
) {
74 qs
[i
].dispose(disposeId
, throwable
);
78 public static ThreadId
getThreadId() {
79 Thread t
= Thread
.currentThread();
80 if (t
instanceof JobQueue
.JobDispatcher
) {
81 return ((JobQueue
.JobDispatcher
) t
).getThreadId();
84 synchronized (threadIdMap
) {
85 id
= (ThreadId
) threadIdMap
.get(t
);
87 id
= ThreadId
.createFresh();
88 threadIdMap
.put(t
, id
);
95 private static final WeakHashMap threadIdMap
= new WeakHashMap();
96 private final HashMap jobQueues
= new HashMap();