>(seems as  the packets are filled in the order sent out, but
>I get them back out of order sometimes).

That is probably because your listener is taking a very long time to
process each event.  The EventListenerHelper tries to get each event
to you as fast as it can, which means if you are still processing the
last packet it will start a new Thread to get the next one to you.
That's probably why you're getting out-of-order packets, and why there
are a lot of Threads being created (there was also a Thread problem
with the RunnableManager before 8/18/2002).

I have known for a while the EventListenerHelper needs changing to be
more fair on a per-listener basis, currently it's on a per-event
basis.  That is, a single Thread is used to deliver each event, and
the next Event gets a new Thread, if the old Thread is still in use.
That ensures that each event will get fired; but an earlier listener
may block later listeners.  A more fair approach is one Thread per
listener, so that listeners can block themselves from getting later
events, but can't block others.  Slightly more complicated to
implement but not too bad (basically just a Hashtable or map of the
current listeners, each one gets their own RunnableManager with an
unlimited max size).


But I don't think you should be using a listener.  Listeners
are nice for _unrequested_ data (like interrupt data) but for data
that you know is going to happen (requested data) then the listener is
just adding overhead; you could instead just asyncSubmit multiple
Lists of IRPs, and then waitUntilCompleted() on each IRP in order -
process it once it's done, and once you process the entire List
resubmit it.  That removes the overhead of the listener and allows you
to do something with your main Thread (or another
submitting/processing Thread you create).


something like this:


/* start it up */
for (int i=0; i<numberOfLists; i++)
  pipe.asyncSubmit(myList[i]);

int listNum = 0, irpNum = 0;

while (true) {
  UsbIrp irp = (UsbIrp)myList[listNum].get(irpNum);
  irp.waitUntilCompleted();
  processUsbIrp(irp);
  irpNum++;
  if (numberIrpsInEachList == irpNum) {
    /* reset UsbIrps if needed here */
    pipe.asyncSubmit(myList[listNum]);
    irpNum = 0;
    listNum++;
  }
  if (numberOfLists == listNum)
    listNum = 0;
}


-- 
Dan Streetman
[EMAIL PROTECTED]
--------------------------------------------------
186,282 miles per second:
It isn't just a good idea, it's the law!



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
javax-usb-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel

Reply via email to