2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.giraph
.utils
;
20 import com
.google
.common
.util
.concurrent
.ThreadFactoryBuilder
;
22 import java
.util
.concurrent
.ThreadFactory
;
25 * Utility class for thread related functions.
27 public class ThreadUtils
{
30 * Utility class. Do not inherit or create objects.
32 private ThreadUtils() { }
35 * Creates new thread factory with specified thread name format.
37 * @param nameFormat defines naming format for threads created by
39 * @param exceptionHandler handles uncaught exceptions in all threads
40 * produced created thread factory
41 * @return new thread factory with specified thread name format and
44 public static ThreadFactory
createThreadFactory(
46 Thread
.UncaughtExceptionHandler exceptionHandler
) {
47 ThreadFactoryBuilder builder
= new ThreadFactoryBuilder().
48 setNameFormat(nameFormat
);
49 if (exceptionHandler
!= null
) {
50 builder
.setUncaughtExceptionHandler(exceptionHandler
);
52 return builder
.build();