Skip to content

Commit 1f23f8d

Browse files
authored
Merge pull request jruby#9343 from kares/native-thread-id-10
[compat] Thread#native_thread_id: using Java thread-id
2 parents c505abd + 2f1a721 commit 1f23f8d

2 files changed

Lines changed: 4 additions & 16 deletions

File tree

core/src/main/java/org/jruby/RubyThread.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import java.io.IOException;
3737
import java.io.Writer;
38-
import java.lang.management.ManagementFactory;
38+
3939
import java.lang.ref.WeakReference;
4040
import java.nio.ByteBuffer;
4141
import java.nio.channels.Channel;
@@ -1503,21 +1503,10 @@ public IRubyObject raise(ThreadContext context, IRubyObject[] args, Block block)
15031503
public IRubyObject native_thread_id(ThreadContext context) {
15041504
if (!isAlive()) return context.nil;
15051505

1506-
String encodedString = ManagementFactory.getRuntimeMXBean().getName();
1507-
int atIndex = encodedString.indexOf('@');
1508-
1509-
// Undocumented format: 1761769@localhost.localdomain
1510-
if (atIndex != -1) {
1511-
try {
1512-
int id = Integer.parseInt(encodedString.substring(0, atIndex));
1513-
1514-
return asFixnum(context, id);
1515-
} catch (NumberFormatException e) {
1516-
// if we fail to parse this we will just act like we don't support it
1517-
}
1518-
}
1506+
Thread nativeThread = getNativeThread();
1507+
if (nativeThread == null) return context.nil;
15191508

1520-
return context.nil; // Not supported or failed to extract id
1509+
return asFixnum(context, nativeThread.threadId());
15211510
}
15221511

15231512
private IRubyObject genericRaise(ThreadContext context, RubyThread currentThread, IRubyObject... args) {

spec/tags/ruby/core/thread/native_thread_id_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)