Skip to content

Commit

Permalink
remove securityManager (#24562)
Browse files Browse the repository at this point in the history
Co-authored-by: annie-mac <[email protected]>
  • Loading branch information
xinlian12 and annie-mac authored Oct 20, 2021
1 parent d5e5f7a commit d7181b9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import com.azure.cosmos.CosmosAsyncContainer
import com.azure.cosmos.spark.diagnostics.ILogger
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.ObjectNode
import org.slf4j.LoggerFactory

import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.ThreadFactory
import java.util.concurrent.atomic.AtomicInteger

private object SparkUtils {

Expand Down Expand Up @@ -47,20 +46,11 @@ private object SparkUtils {
}

private class DaemonThreadFactory extends ThreadFactory {
private val securityManager = System.getSecurityManager
private val threadGroup = Option.apply(securityManager) match {
case Some(s) => s.getThreadGroup
case None => Thread.currentThread.getThreadGroup
}
private val threadNumber = new AtomicInteger(1)
private val namePrefix = "cosmos-spark-daemon-pool-" + DaemonThreadFactory.poolNumber.getAndIncrement + "-thread-"

override def newThread(r: Runnable): Thread = {
val t = new Thread(
threadGroup,
r,
namePrefix + threadNumber.getAndIncrement,
0)
val t = new Thread(r, namePrefix + threadNumber.getAndIncrement)
if (!t.isDaemon) t.setDaemon(true)
if (t.getPriority != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY)
t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@ class RntbdThreadFactory implements ThreadFactory {
private final boolean daemon;
private final String name;
private final int priority;
private final ThreadGroup threadGroup;
private final AtomicInteger threadCount;

@SuppressWarnings("removal")
RntbdThreadFactory(final String name, final boolean daemon, final int priority) {

final SecurityManager securityManager = System.getSecurityManager();

this.threadGroup = securityManager != null
? securityManager.getThreadGroup()
: Thread.currentThread().getThreadGroup();

this.daemon = daemon;
this.name = name;
this.priority = priority;
Expand All @@ -40,7 +32,7 @@ class RntbdThreadFactory implements ThreadFactory {
public Thread newThread(final Runnable runnable) {

final String name = lenientFormat(NAME_TEMPLATE, this.name, this.threadCount.incrementAndGet());
final Thread thread = new Thread(this.threadGroup, runnable, name, 0);
final Thread thread = new Thread(runnable, name);

if (thread.isDaemon() != this.daemon) {
thread.setDaemon(this.daemon);
Expand Down

0 comments on commit d7181b9

Please sign in to comment.