Made some fields volatile.This gaurantees that the field becomes visible
to all readers (other threads in particular) after a write operation
completes on it. Without volatile, readers could see some non-updated
value.Notethat volatile may make the code slower.