Hi!

I wrote a simple test  (Java) program that puts a couple of items into
the cache (1.4.4) from the main thread, then spaws a thread for each
item that reads the item and after all threads have finished doing so
deletes the item subsequently from the main thread again. Doesn't
work. The first time I run the program the item can be read but not be
deleted because they supposedly do not exist.

I don't get it, can somebody explain what I am doing wrong?

import com.surftools.BeanstalkClient.Job;
import com.surftools.BeanstalkClientImpl.ClientImpl;

import java.util.HashSet;
import java.util.Set;

public class ThreadingTest {
    public static final void main(String[] args) throws
InterruptedException {
        final ClientImpl client = new ClientImpl("localhost", 11300);

        final int max = 3;

        final Set<Long> jobIds = new HashSet<Long>(max);
        for (int i = 0; i < max; i++) {
            final long jobId = client.put(0, 0, 5, "hello
world".getBytes());
            jobIds.add(jobId);
            System.out.println("put " + jobId);
        }

        Thread[] threads = new Thread[max];

        for (int i = 0; i < threads.length; i++)
            (threads[i] = new Thread(new Runnable() {

                @Override
                public void run() {
                    final Job job = client.reserve(null);
 
System.out.println(Thread.currentThread().getName() + ": " +
job.getJobId());
                }
            })).start();

        for (Thread t : threads)
            t.join();

        Thread.sleep(1000);

        for (long jobId : jobIds) {
            boolean b = client.delete(jobId);
            System.out.println(jobId + ": " + b);
        }
    }
}

output:

put 1
put 2
put 3
Thread-2: 3
Thread-0: 1
Thread-1: 2
NOT_FOUND
1: false
NOT_FOUND
2: false
NOT_FOUND
3: false

-- 
You received this message because you are subscribed to the Google Groups 
"beanstalk-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/beanstalk-talk?hl=en.

Reply via email to