I have a multithreaded application in Java. In the run method of one of the threads, I have a
System.out.println("Print something something something")
statement. The problem I have is that sometimes, the output I get from this print is not "Print something something something"
but "something Print something something"
and some other variations. Please what is the cause of this? The method I am calling in my run method is shown below.
public synchronized void generateRequests() {
String name;
int qty;
int index = 0;
System.out.print("Customer " + custId + " requests, ");
for (Item i : items) {
name = i.getName();
qty = randNoGenerator(0, 10);
items.set(index, new Item(name, qty));
index++;
System.out.print(qty + " " + name + ", ");
}
s.serviceRequests(this);
}