Is there any easy way to return data from a Gradle 5.6+ WorkAction performed by a WorkQueue back to the thread that submitted the WorkAction?
Currently, I pass data by having a static ConcurrentMap<Long, MyConcurrentDataStructure> that maps from the thread ID of the thread that submits the work to a concurrent data structure. The thread ID is passed a Long parameter to the WorkAction, which uses it as a key to the concurrent data structure from the ConcurrentMap, which it then modifies.
This seems overly complicated. Is there any simpler way to return this data? If not, I think that adding some sort of callback mechanism would be useful. To avoid concurrency issues, the callback code should only ever run for the data from one worker at one time; this should be enforced by enqueuing callback parameters into a FIFO queue, and locking reading from the queue as long as a callback is currently executing.
Is there any easy way to return data from a Gradle 5.6+ WorkAction performed by a WorkQueue back to the thread that submitted the WorkAction?
Don’t use a static variable, workers might be loaded via a different classloader or even running on a separate daemon jvm (so will not share static state). Write it to a file (eg json/xml/properties). You could also serialize an object to/from a file via ObjectOutputStream.
Each worker can write a separate file, then the main thread waits for all to complete and collects them all (eg all files in a specific directory)
I just threw together a wrapper for the worker executor API which allows you to specify jobs as Callable and under the hood it does all the serializing / deserializing to files.