All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gridgain.grid.thread.GridThread Maven / Gradle / Ivy

Go to download

Java-based middleware for in-memory processing of big data in a distributed environment.

There is a newer version: 6.2.1-p1
Show newest version
/* 
 Copyright (C) GridGain Systems. All Rights Reserved.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/*  _________        _____ __________________        _____
 *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
 *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
 *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
 *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
 */

package org.gridgain.grid.thread;

import org.gridgain.grid.util.typedef.internal.*;
import org.gridgain.grid.util.worker.*;

import java.util.concurrent.atomic.*;

/**
 * This class adds some necessary plumbing on top of the {@link Thread} class.
 * Specifically, it adds:
 * 
    *
  • Consistent naming of threads
  • *
  • Dedicated parent thread group
  • *
  • Backing interrupted flag
  • *
* Note: this class is intended for internal use only. */ public class GridThread extends Thread { /** Default thread's group. */ private static final ThreadGroup DFLT_GRP = new ThreadGroup("gridgain"); /** Number of all grid threads in the system. */ private static final AtomicLong threadCntr = new AtomicLong(0); /** Boolean flag indicating of this thread is currently processing message. */ private boolean procMsg; /** * Creates thread with given worker. * * @param worker Runnable to create thread with. */ public GridThread(GridWorker worker) { this(DFLT_GRP, worker.gridName(), worker.name(), worker); } /** * Creates grid thread with given name for a given grid. * * @param gridName Name of grid this thread is created for. * @param threadName Name of thread. * @param r Runnable to execute. */ public GridThread(String gridName, String threadName, Runnable r) { this(DFLT_GRP, gridName, threadName, r); } /** * Creates grid thread with given name for a given grid with specified * thread group. * * @param grp Thread group. * @param gridName Name of grid this thread is created for. * @param threadName Name of thread. * @param r Runnable to execute. */ public GridThread(ThreadGroup grp, String gridName, String threadName, Runnable r) { super(grp, r, createName(threadCntr.incrementAndGet(), threadName, gridName)); } /** * Creates new thread name. * * @param num Thread number. * @param threadName Thread name. * @param gridName Grid name. * @return New thread name. */ private static String createName(long num, String threadName, String gridName) { return threadName + "-#" + num + '%' + gridName + '%'; } /** * @param procMsg Flag indicating whether thread is currently processing message. */ public void processingMessage(boolean procMsg) { this.procMsg = procMsg; } /** * @return Flag indicating whether thread is currently processing message. */ public boolean processingMessage() { return procMsg; } /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridThread.class, this, "name", getName()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy