StackWalker API৷ Java 9,-এ একটি নতুন বৈশিষ্ট্য এবং এটি পূর্বসূরির কর্মক্ষমতা উন্নত করে স্ট্যাক ট্র্যাক উপাদান। এটি ব্যতিক্রম এর ক্ষেত্রে স্ট্যাক উপাদানগুলিকে ফিল্টার করার একটি উপায়ও প্রদান করতে পারে অথবা অ্যাপ্লিকেশন বুঝতে আচরণ . জাভা 9-এ, স্ট্যাক ট্রেস অ্যাক্সেস করার উপায় খুবই সীমিত এবং একবারে পুরো স্ট্যাকের তথ্য প্রদান করে।
নীচের উদাহরণে, আমাদের স্ট্যাক ফ্রেমের সমস্ত বৈশিষ্ট্য প্রিন্ট করতে হবে
উদাহরণ
import java.lang.StackWalker.StackFrame;
import java.util.*;
import java.util.stream.*;
import java.lang.StackWalker.Option;
public class AllAttributesTest {
public static void main(String args[]) {
System.out.println("Java 9 Stack Walker API - Print all attributes in stack frame");
StackWalker newWalker = StackWalker.getInstance(Option.RETAIN_CLASS_REFERENCE);
List<StackWalker.StackFrame> stackFrames = newWalker.walk(frames -> frames.limit(1).collect(Collectors.toList()));
stackFrames.forEach(test-> {
System.out.printf("[Bytecode Index] %d%n", test.getByteCodeIndex());
System.out.printf("[Class Name] %s%n", test.getClassName());
System.out.printf("[Declaring Class] %s%n", test.getDeclaringClass());
System.out.printf("[File Name] %s%n", test.getFileName());
System.out.printf("[Method Name] %s%n", test.getMethodName());
System.out.printf("[Is Native] %b%n", test.isNativeMethod());
System.out.printf("[Line Number] %d%n", test.getLineNumber());
});
}
} আউটপুট
Java 9 Stack Walker API - Print all attributes in stack frame [Bytecode Index] 21 [Class Name] AllAttributesTest [Declaring Class] class AllAttributesTest [File Name] AllAttributesTest.java [Method Name] main [Is Native] false [Line Number] 10