commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott.Wu (JIRA)" <j...@apache.org>
Subject [jira] [Created] (VFS-504) Duplicate notifications if there are multiple subscription to same file
Date Thu, 21 Nov 2013 11:58:35 GMT
Scott.Wu created VFS-504:
----------------------------

             Summary: Duplicate notifications if there are multiple subscription to same file
                 Key: VFS-504
                 URL: https://issues.apache.org/jira/browse/VFS-504
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 2.0
            Reporter: Scott.Wu
            Priority: Critical


I initiate 2 threads to monitor same file. I hope to get 2 notifications if I changed file,
but finally I got 4. I think the root cause is the listener is bound to file object, but event
will be fired by filemonitor, each monitor will point to same file which have 2 listeners.

// main process
 for (int i = 0; i < 2; i++) {
            Thread thread = new Thread(new Runnable() {
                public void run() {
                    try {
                        IPAdapterFileMonitor monitor = IPAdapterFileMonitor.getInstance();
                        monitor.startMonitor();
                    } catch (FileSystemException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });

            thread.start();
        }

//method in thread.
 public void startMonitor() throws FileSystemException{
         DefaultFileMonitor fm = new DefaultFileMonitor(new IPAdapterFileListener());
         fm.addFile(targetFile);
         fm.start();
         System.out.println(Thread.currentThread().getId());
    }



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message