Database Reference
In-Depth Information
return
value;
}
@SuppressWarnings("unchecked")
public
T deserialize(
byte
[] bytes) {
ByteArrayInputStream bin =
new
ByteArrayInputStream(bytes);
Object object =
null
;
try
{
ObjectInput in =
new
ObjectInputStream(bin);
object = in.readObject();
in.close();
}
catch
(IOException e) {
}
catch
(ClassNotFoundException e) { }
try
{
bin.close();
}
catch
(IOException e2) { }
return
(T)object;
}
}
Now, all that remains is to start adding items to the queue. This simple
example implements Runnable and a simple run loop that adds items to the
queue after a random wait of up to 2 seconds:
Random rng =
new
Random();
public void
run() {
System.
out
.println("Starting Producer");
boolean
cont =
true
;
long
id = 0;
while
(cont) {
try
{
queue.put(
new
WorkUnit(id++,"Next Work Unit
"+id));
System.
out
.println("Added item");
}
catch
(Exception e1) {
e1.printStackTrace();
}
try
{
Thread.
sleep
(rng.nextInt(1000));