Skip to content

Commit

Permalink
Support use virtual thread as platform thread
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Jun 28, 2024
1 parent 453a0d2 commit 88c7024
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.dubbo.common.utils;

import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;

import java.lang.Thread.UncaughtExceptionHandler;

public class DubboUncaughtExceptionHandler implements UncaughtExceptionHandler {
private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(DubboUncaughtExceptionHandler.class);

private static final DubboUncaughtExceptionHandler INSTANCE = new DubboUncaughtExceptionHandler();

private DubboUncaughtExceptionHandler() {}

public static DubboUncaughtExceptionHandler getInstance() {
return INSTANCE;
}

@Override
public void uncaughtException(Thread t, Throwable e) {
logger.error(LoggerCodeConstants.INTERNAL_ERROR, "", "", "Unexpected exception occurred in thread", e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public Thread newThread(Runnable runnable) {
String name = mPrefix + mThreadNum.getAndIncrement();
Thread ret = new Thread(mGroup, runnable, name, 0);
ret.setDaemon(mDaemon);
ret.setUncaughtExceptionHandler(DubboUncaughtExceptionHandler.getInstance());
return ret;
}

Expand Down
Loading

0 comments on commit 88c7024

Please sign in to comment.