Skip to main content

Java 25 Feature: Structured Task Scope

 Structured Task Scope




So
in the above code what is happening, code line var scope = new StructuredTaskScope<>() is opening a scop (consider it as a container) and any task (thread) which is being opened or executed in this scop will be consistent to other tasks in that same scope.

scope.join() is making the both the tasks to execute and finish together. 
scope.throwIfFailed() which means if any task is failed then other executed tasks will also come on halt.

e.g take this scenario where you want to update user password in diff servers. if password update failed on any server then we can discard the whole process so that user doesn't have to use old and new password on diff servers that would be very sus infra.





Comments

Popular posts from this blog

Understanding the usage of underscore( _ ) of Python for beginner. On Python Hunter

Introduction: Just like you, a newbie in python scripting language, me too was confused about lot of new things in python that are not valid or available in other languages like Java, .Net etc. Just like other things i had seen the use of '_' underscore in python, at beginning level that flabbergasted me for a while.      With some research and practice i have summarised the following usage of '_' underscore in python. Hope you will find it helpful at beginning level. First Usage : Hold the previous output value. When used in interpreter. 1 2 3 4 5 6 7 _ = input () # For example you typed '5' print (_) # This will print '5' print ( int ( _ ) * int ( _ ) ) # This will print '25' print ( int ( _ ) + 10 ) The above will print '15', because last input was "5" and in above   line of code is producing '25' as output but not being handl...

Understanding "with" keyword in python, on Python Hunter

J ust like anything in python, keyword "with" is introduced in python to make the things little easy. Imagine a situation where you have to manage the resources e.g opening file and closing them after the code is executed on file. To achieve this sort of task we have to write the code as follow:      Download   But if you do it often you could do this as follow to make the code reusable: Download But why do you need to do this when you know that you have to execute the only for once.  To answer this question  python-dev team finally came up with following approach: Download  Note:- Make sure you have "file.txt" and python code file in same dir. The "with"  keyword replaces the try finally block. "with" keyword executes the openFileClass() context manager and internally calls the __enter__(self) method, and whatever is being returned from __enter__(self) method is being stored in tar...

Set in python on Python hunter blog by pran sukh

The  set can contain  elements or members of  anything: numbers, characters, words, names, letters of the alphabet, even other sets and tuples. Sets are usually denoted with capital letters. Set is a data type in python and can hold any number of elements and any type of data in it. Even set data type is similar to other data types in python like list and tuple still there are some differences. Only unique object will be inserted as set element, duplicate or repeated elements will be removed from set object. Set object can not have list and dictionary object as element but we can pass a single list or dictionary object to Set() method and turn the list or dictionary into individual elements. This is the shortest method to remove the duplicates from list object. No need to filter the duplicate from dictionary object as it is already taken in care by dictionary. It is wise and error free to have tuple object as set's elements. Even the set contain the immu...