microsoft / Intune-Resource-Access

Sample code and scripts for interfacing with the Intune Resource Access APIs.
MIT License
54 stars 58 forks source link

Use same thread executor #106

Open markscottwright opened 3 years ago

markscottwright commented 3 years ago

The current code is performing authentication calls on ExecutorService that it then cleans up in a finalize method. I suspect this is how the original C# code does it. However, finalize doesn't work in java the way it does in C# and as written the code will prevent the JVM from exiting unless at least two GC calls have occurred since an ADALClientWrapper has been constructed (create a simple main that does nothing but make an IntuneClient call to demonstrate this - the program will hang on exit). It also will keep allocating new OS threads between GC calls.

The library as written makes no use of the possible concurrency offered by adal4j's ExecutorService-based design, so I replaced the current ExecutorService with a "run on the current thread" version. It should be more efficient, will not hold onto the JVM and will not allocate unnecessary OS threads.