Roberto Grena algorithm implementation in java language in a single thread of execution