java - How do i set up a DelayQueue's Delay -


I'm just starting coding in Java, I'm struggling with a delay setting,

I wanted to do this much,

  Delayqu Q = New Delayu (); If (counter & amp; ;;) {queue.offer (integer, * a custom delay *)} other {queue.offer (integer, * a different custom delay *)}   

I am just trying to learn all basic things and have been read on the API and do not seem to understand it.

In advance thanks

delayu of a certain delay Keeps internal elements until the time limit expires. Elements the interface java.util.concurrent.Delayed .

For example, I have extended a class DelayedTest delayed interface. It will compare and obtain () method

  public class A {public static zero main (string ... args) {DELUQUEUE DUKE = NEW DELIVE (); DeleyedTest ob1 = New DeleyedTest (10); DeleyedTest ob2 = New DeleyedTest (5); DeleyedTest ob3 = New DeleyedTest (15); Dq.offer (OB1); Dq.offer (ob2); Dq.offer (ob3); Iterator IRR = decontroller (); While (IRHISEXEx) {DealEdest Test DT = (Delayed Test) ITR Nxt (); Println (dt.deleyTime); }}} Class DeleyedTest apply delay {public long delimiters = 0; DeleyedTest (Long Delight) {this.deleyTime = Deliime; } Compare override public int (delayed ob) {if (this delitime) ((Delayed Test)). Delay (return); Return -1; } And if (this.deleyTime> (DeleyedTest) Ob) .deleyTime) {Return 1; } Return 0; } @ Override Public Long Late Della (Time Unit Unit) {unit.convert (DeliTyme-System.contentime milliseconds), time unit. Nanosconds); Return 0; }}   

Result:

 5 10 15   

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -