Menu ▾ ▴

Exception when using JNotify

Help
Blob
2012-05-11
2013-05-20
  • Blob

    Blob - 2012-05-11

    Hi there!

    My code looks like this:

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.util.Calendar;
    import net.contentobjects.jnotify.JNotify;
    import net.contentobjects.jnotify.JNotifyListener;
    public class FolderListener {
        public void sample() throws Exception
        {
            // path to watch
            String path = System.getProperty("C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps\\ITPDP\\JSP\\Pictures");
            // watch mask, specify events you care about,
            // or JNotify.FILE_ANY for all events.
            int mask = JNotify.FILE_CREATED;
            // watch subtree?
            boolean watchSubtree = true;
            System.out.println("1...");
            // add actual watch
            int watchID = JNotify.addWatch(path, mask, watchSubtree, new MyFolderListener());
            // sleep a little, the application will exit if you
            // don't (watching is asynchronous), depending on your
            // application, this may not be required
            System.out.println("2...");
            Thread.sleep(1000000);
            System.out.println("2½...");
            // to remove watch the watch
            boolean res = JNotify.removeWatch(watchID);
            if (!res) {
                // invalid watch ID specified.
            }
        }
        class MyFolderListener implements JNotifyListener
        {
            @Override
            public void fileRenamed(int wd, String rootPath, String oldName, String newName)
            {
            }
            @Override
            public void fileModified(int wd, String rootPath, String name)
            {
            }
            @Override
            public void fileDeleted(int wd, String rootPath, String name)
            {
            }
            @Override
            public void fileCreated(int wd, String rootPath, String name)
            {
                try
                {
                    System.out.println("3...");
                    String connectionURL = "jdbc:mysql://[our database url]";
                    String myDriver = "com.mysql.jdbc.Driver";
                    Class.forName(myDriver).newInstance();
                    Connection con = DriverManager.getConnection(connectionURL);
                    String query = "INSERT INTO Conversations (ConversationID, Content1, Content2, Date) VALUES (587, '', 'http://localhost:8080/ITPDP/JSP/Pictures/" + name + ".jpg', " + Calendar.getInstance().getTimeInMillis() + ")";
                    //Create a Statement class to execute the SQL statement
                    PreparedStatement stmt = con.prepareStatement(query);
                    stmt.executeUpdate();
                    System.out.println("4...");
                    con.close();
                }
                catch (SQLException e) {
                    e.printStackTrace();
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        public static void main(String[] args) throws Exception {
            System.out.println("0...");
           //System.out.println(System.getProperties());
            new FolderListener().sample();
        }
    }
    

    But it only runs for a very short time, and never gets past the line:

    int watchID = JNotify.addWatch(path, mask, watchSubtree, new MyFolderListener());
    

    "0…" and "1…" is printed in the console, but it never makes it to "2…". No errors are shown and no exceptions are thrown.

    I tried using the sample code (http://jnotify.sourceforge.net/sample.html), but running this causes the following message:


    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006d92617c, pid=2592, tid=1744
    #
    # JRE version: 6.0_27-b07
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (20.2-b06 mixed mode windows-amd64 compressed oops)
    # Problematic frame:
    # V 
    #
    # If you would like to submit a bug report, please visit:
    #   http://java.sun.com/webapps/bugreport/crash.jsp
    #

    ----------  T H R E A D  ----------

    Current thread (0x000000000079c000):  JavaThread "main"

    siginfo: ExceptionCode=0xc0000005, reading address 0x0000000000000000

    Registers:
    RAX=0x0000000000000000, RBX=0x000000000079c000, RCX=0x0000000000000c00, RDX=0x0000000000000000
    RSP=0x00000000028ef6c0, RBP=0x0000000000000000, RSI=0x0000000000000000, RDI=0x0000000000000000
    R8 =0x0000000000000000, R9 =0x000000000000017f, R10=0x0000000002901359, R11=0x000000006d9f23d0
    R12=0x0000000000000001, R13=0x000000077c6caf90, R14=0x00000000028ef838, R15=0x000000000079c000
    RIP=0x000000006d92617c, EFLAGS=0x0000000000010202

    Top of Stack: (sp=0x00000000028ef6c0)
    0x00000000028ef6c0:   0000000000000000 000000000079ca00
    0x00000000028ef6d0:   0000000000000000 0000000000000000
    0x00000000028ef6e0:   000000000079c000 00000000028ef838
    0x00000000028ef6f0:   000000077c6caf90 000000006f18349d
    0x00000000028ef700:   000000000079c1d0 000000000000017f
    0x00000000028ef710:   000000077c673e10 0000000000000000
    0x00000000028ef720:   00000000028ef800 0000000000797790
    0x00000000028ef730:   0000000000797700 000000006d888094
    0x00000000028ef740:   000000000079caf0 0000000002901212
    0x00000000028ef750:   000000077c6caf90 000000077c673e10
    0x00000000028ef760:   0000000000200020 00000000028ef800
    0x00000000028ef770:   0000000000000000 0000000002901386
    0x00000000028ef780:   00000000028f4ed0 0000000000000000
    0x00000000028ef790:   00000000028ef978 00000000028ef910
    0x00000000028ef7a0:   0000000000000001 000000000079c000
    0x00000000028ef7b0:   00000000028f4ed0 0000000000000000

    Instructions: (pc=0x000000006d92617c)
    0x000000006d92615c:   8b cb e8 2d 11 0e 00 48 85 ff c7 83 48 02 00 00
    0x000000006d92616c:   06 00 00 00 74 03 c6 07 01 40 38 35 d4 46 60 00
    0x000000006d92617c:   48 8b 55 00 48 63 05 e5 ca 5e 00 4c 89 6c 24 28
    0x000000006d92618c:   4c 63 2c 10 74 2b 48 63 05 db ca 5e 00 44 8b 04

    Register to memory mapping:

    RAX=0x0000000000000000 is an unknown value
    RBX=0x000000000079c000 is a thread
    RCX=0x0000000000000c00 is an unknown value
    RDX=0x0000000000000000 is an unknown value
    RSP=0x00000000028ef6c0 is pointing into the stack for thread: 0x000000000079c000
    RBP=0x0000000000000000 is an unknown value
    RSI=0x0000000000000000 is an unknown value
    RDI=0x0000000000000000 is an unknown value
    R8 =0x0000000000000000 is an unknown value
    R9 =0x000000000000017f is an unknown value
    R10=0x0000000002901359 is an Interpreter codelet
    method entry point (kind = native)    2176 bytes
    R11=0x000000006d9f23d0 is an unknown value
    R12=0x0000000000000001 is an unknown value
    R13=0x000000077c6caf90 is an oop
    {method}
    - klass: {other class}
    R14=0x00000000028ef838 is pointing into the stack for thread: 0x000000000079c000
    R15=0x000000000079c000 is a thread

    Stack: ,  sp=0x00000000028ef6c0,  free space=1021k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    V 

    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j  net.contentobjects.jnotify.win32.JNotify_win32.nativeAddWatch(Ljava/lang/String;JZ)I+0
    j  net.contentobjects.jnotify.win32.JNotify_win32.addWatch(Ljava/lang/String;JZ)I+3
    j  net.contentobjects.jnotify.win32.JNotifyAdapterWin32.addWatch(Ljava/lang/String;IZLnet/contentobjects/jnotify/JNotifyListener;)I+5
    j  net.contentobjects.jnotify.JNotify.addWatch(Ljava/lang/String;IZLnet/contentobjects/jnotify/JNotifyListener;)I+7
    j  offentlig.TestFolderListener.sample()V+22
    j  offentlig.TestFolderListener.main([Ljava/lang/String;)V+9
    v  ~StubRoutines::call_stub

    ----------  P R O C E S S  ----------

    Java Threads: ( => current thread )
      0x00000000069fe000 JavaThread "Low Memory Detector" daemon
      0x00000000069f5800 JavaThread "C2 CompilerThread1" daemon
      0x00000000069e1000 JavaThread "C2 CompilerThread0" daemon
      0x00000000069e0000 JavaThread "Attach Listener" daemon
      0x00000000069dd800 JavaThread "Signal Dispatcher" daemon
      0x0000000006987800 JavaThread "Finalizer" daemon
      0x0000000006987000 JavaThread "Reference Handler" daemon
    =>0x000000000079c000 JavaThread "main"

    Other Threads:
      0x000000000697b800 VMThread 
      0x0000000006a10000 WatcherThread 

    VM state:not at safepoint (normal execution)

    VM Mutex/Monitor currently owned by a thread: None

    Heap
    PSYoungGen      total 37824K, used 648K [0x00000007d5cb0000, 0x00000007d86e0000, 0x0000000800000000)
      eden space 32448K, 2% used [0x00000007d5cb0000,0x00000007d5d523e0,0x00000007d7c60000)
      from space 5376K, 0% used [0x00000007d81a0000,0x00000007d81a0000,0x00000007d86e0000)
      to   space 5376K, 0% used [0x00000007d7c60000,0x00000007d7c60000,0x00000007d81a0000)
    PSOldGen        total 86400K, used 0K [0x0000000781600000, 0x0000000786a60000, 0x00000007d5cb0000)
      object space 86400K, 0% used [0x0000000781600000,0x0000000781600000,0x0000000786a60000)
    PSPermGen       total 21248K, used 2869K [0x000000077c400000, 0x000000077d8c0000, 0x0000000781600000)
      object space 21248K, 13% used [0x000000077c400000,0x000000077c6cd768,0x000000077d8c0000)

    Code Cache  [0x00000000028f0000, 0x0000000002b60000, 0x00000000058f0000)
    total_blobs=177 nmethods=2 adapters=129 free_code_cache=49942080 largest_free_block=12352

    Dynamic libraries:
    0x0000000000400000 - 0x000000000042e000 C:\Program Files\Java\jre6\bin\javaw.exe
    0x00000000779d0000 - 0x0000000077b79000 C:\Windows\SYSTEM32\ntdll.dll
    0x00000000775a0000 - 0x00000000776bf000 C:\Windows\system32\kernel32.dll
    0x000007fefe190000 - 0x000007fefe1fc000 C:\Windows\system32\KERNELBASE.dll
    0x0000000075240000 - 0x000000007527f000 C:\Program Files\AVAST Software\Avast\snxhk64.dll
    0x000007feffa50000 - 0x000007feffb2b000 C:\Windows\system32\ADVAPI32.dll
    0x000007fefea00000 - 0x000007fefea9f000 C:\Windows\system32\msvcrt.dll
    0x000007fefe880000 - 0x000007fefe89f000 C:\Windows\SYSTEM32\sechost.dll
    0x000007feffb60000 - 0x000007feffc8d000 C:\Windows\system32\RPCRT4.dll
    0x00000000776c0000 - 0x00000000777ba000 C:\Windows\system32\USER32.dll
    0x000007feff8b0000 - 0x000007feff917000 C:\Windows\system32\GDI32.dll
    0x000007fefe8b0000 - 0x000007fefe8be000 C:\Windows\system32\LPK.dll
    0x000007fefe5f0000 - 0x000007fefe6b9000 C:\Windows\system32\USP10.dll
    0x000007feffb30000 - 0x000007feffb5e000 C:\Windows\system32\IMM32.DLL
    0x000007feff940000 - 0x000007feffa49000 C:\Windows\system32\MSCTF.dll
    0x000007fefdd50000 - 0x000007fefdd8c000 C:\Windows\system32\nvinitx.dll
    0x000000006d7f0000 - 0x000000006dfa8000 C:\Program Files\Java\jre6\bin\server\jvm.dll
    0x000007fefbf50000 - 0x000007fefbf8b000 C:\Windows\system32\WINMM.dll
    0x000000006d760000 - 0x000000006d76e000 C:\Program Files\Java\jre6\bin\verify.dll
    0x000000006d3b0000 - 0x000000006d3d7000 C:\Program Files\Java\jre6\bin\java.dll
    0x000000006d7b0000 - 0x000000006d7c2000 C:\Program Files\Java\jre6\bin\zip.dll
    0x000000006f180000 - 0x000000006f23e000 C:\Program Files\Java\jre6\bin\jnotify_64bit.dll
    0x0000000077ba0000 - 0x0000000077ba7000 C:\Windows\system32\PSAPI.DLL
    0x000007fef76b0000 - 0x000007fef77d5000 C:\Windows\system32\dbghelp.dll

    VM Arguments:
    jvm_args: -Dfile.encoding=Cp1252
    java_command: offentlig.TestFolderListener
    Launcher Type: SUN_STANDARD

    Environment Variables:
    PATH=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Trend Micro\AMSP;C:\Program Files\Java\jdk1.6.0_27\bin
    USERNAME=Nies
    OS=Windows_NT
    PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel

    ----------  S Y S T E M  ----------

    OS: Windows 7 , 64 bit Build 7601 Service Pack 1

    CPU:total 8 (4 cores per cpu, 2 threads per core) family 6 model 42 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, ht

    Memory: 4k page, physical 8291392k(5470828k free), swap 16580932k(13294680k free)

    vm_info: Java HotSpot(TM) 64-Bit Server VM (20.2-b06) for windows-amd64 JRE (1.6.0_27-b07), built on Jul 19 2011 01:08:22 by "java_re" with MS VC++ 8.0 (VS2005)

    time: Fri May 11 10:03:20 2012
    elapsed time: 0 seconds


    I put the file called "jnotify_64bit.dll" in both the folder C:\Windows\SysWOW64 and the folder C:\Program Files\Java\jre6\bin. I also put the "libjnotify.so" in the previously mentioned java folder.

    Have you any idea what could be caused this?

    Really hope you can help.

    Have a nice day ;)

     

Log in to post a comment.