Difficult communication with processing

My question is, how do i read the Serial.write communication from arduino with processing, for then to assign a task to processing?

First, that is a Processing question, not an Arduino question.

Second, you are spamming Processing unmercifully. You should send data only when the state of a pin changes. See the state change detection example.