Importing Relationships in Parallel is slow

I'm a bit new to the Neo4j, cypher and apoc.

I have this custom apoc function that is similar to apoc.periodic.iterate which is a java procedure that bins and create relationships in rounds and ensure no two nodes are ever written to at the same time.
This is the code basically copying for our use.
https://github.com/Lnofeisone/graph-iterateRelationship/blob/master/IterateRelationship.java

The import is from a rmdbs to neo4j.
We are trying to transition from Neo 3.5 --> Neo 4.4 Community Edition
The data size is probably over 10 million nodes

I updated the some of the IterateRelationship.java to match the APOC 4.4 API

Previously the processing time was quick on neo4j 3.5. We are testing now Neo4j 4.4 CE and the custom function is quite slow.

while (iteratorThreads.stream().anyMatch(x -> !x.isRetired()) &&iteratorThreads.stream().filter(x -> !x.isRetired()).allMatch(x -> !x.isFree())) {
		while (iteratorThreads.stream().filter(x -> !x.isRetired()).allMatch(IteratorThread::isWorking)) { // none done yet, block for a bit
			LockSupport.parkNanos(1000);}
// do work
}

So I noticed this section of code takes a long time to complete. From what I can guess is happening in this section of code is a thread is going to execute the transaction to create a relationship between two nodes. This was fast in 3.5 but slow on 4.4. CE

My question is there some thing to identify the slow down or speed this up?

I am helping @john.e.duong work on this and we are hung up getting a solid understanding of how the core changes from 3.5 to 4.x and newer are affecting this function that is intended to expand apoc.periodic.iterate.

Any guidance would be appreciated.

@john.e.duong was able to identify his error. There was an errant loop that grew exponentially within the function causing it to get stuck and nothing related to the changes within apoc.periodic.iterate.