bump product version to 5.0.4.1
[LibreOffice.git] / jurt / com / sun / star / lib / uno / environments / remote / ThreadPoolManager.java
blob9718264be37971c1735aeecbbe286a132252c685
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 /**
22 * Manages the UNO thread pool factory.
24 * <P>The thread pool factory is a process-wide resource. It is important that
25 * all UNO environments within a process share the same thread pool mechanisms:
26 * if a synchronous UNO call is bridged out from one local UNO environment over
27 * one remote bridge, and recursively calls back into another local UNO
28 * environment over another remote bridge, the code in the second environment
29 * should be executed in the thread that did the original call from the first
30 * environment.</P>
32 * <P>There are both a Java and a native thread pool factory. A pure Java
33 * process will always use the Java thread pool factory. A mixed process uses
34 * the system property <CODE>org.openoffice.native</CODE> (to be set by the
35 * native code that starts the JVM) to determine which implementation
36 * to use.</P>
38 public final class ThreadPoolManager {
39 /**
40 * Creates a thread pool instance.
42 * @return a new thread pool instance; will never be <CODE>null</CODE>.
44 public static synchronized IThreadPool create() {
45 if (useNative) {
46 return new NativeThreadPool();
47 } else {
48 if (javaFactory == null) {
49 javaFactory = new JavaThreadPoolFactory();
51 return javaFactory.createThreadPool();
55 /**
56 * Leads to using the native thread pool factory, unless a Java thread pool
57 * has already been created.
59 * @return <CODE>false</CODE> if a Java thread pool has already been created.
61 public static synchronized boolean useNative() {
62 useNative = javaFactory == null;
63 return useNative;
66 private static boolean useNative
67 = System.getProperty("org.openoffice.native") != null;
68 private static JavaThreadPoolFactory javaFactory = null;
70 private ThreadPoolManager() {} // do not instantiate