Anyone have experience using sun.misc.Unsafe ? I tried using it today and it's giving an error when i run it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import sun.misc.*;
public class UnsafeTester { private static final Unsafe unsafe = Unsafe.getUnsafe(); public static void main(String[] args) { long ptr = unsafe.allocateMemory(512); try{ unsafe.putChar(ptr,'a'); unsafe.putChar(ptr,'b'); System.out.println("Unsafe: " + unsafe.toString()); } finally{ unsafe.freeMemory(ptr); } } }
java.lang.ExceptionInInitializerError Caused by: java.lang.SecurityException: Unsafe at sun.misc.Unsafe.getUnsafe(Unsafe.java:68) at garbage.UnsafeTester.<clinit>(UnsafeTester.java:8) Exception in thread "main" |
I'm not sure exactly how I should go about tackling this one so any help would be great.
