Skip to content

Use java structured concurency to walk all files of a directory (a drive) and execute an action for each file (for example calculate size)

Notifications You must be signed in to change notification settings

FBibonne/file-tree-traverser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Non-blocking and Parallel computing within a file tree in java language : illustrate structrured concurrency

This project illustrates how to use of virtual threads and structured concurrency with java version 25 in order to execute paralleled tasks on each file of a file tree. It uses java virtual threads (JEP 444) combined with structured concurency (JEP 505)

How does it work ?

The project provides a walker method (Traverser.browseFor) which is responsible for executing the method BrowseResult.processFile for each file of a file tree, given an initial instance of BrowseResult.

An instance of BrowseResult is created for every directory which is browsed. So, walking through the content of a root directory, if a file is found, the method processFile is called, if a directory is found a new instance of BrowseResult is created to process the directory in a new structured task scope nested in the current task. StructuredTaskScopes use virtual threads

As The Traverser is designed to produce an aggregated result so, after all the files and all the subdirectories of a directory are processed, results can be aggregated with a call to aggregate().

The previous requirements are implemented in the method traverser.poc.java.filestree.InternalTraverser#call

About

Use java structured concurency to walk all files of a directory (a drive) and execute an action for each file (for example calculate size)

Resources

Stars

Watchers

Forks

Languages