Structured Concurrency to Simplify Java Multithreaded Programming

JEP 428, Structured Concurrency (Incubator), has been promoted from Proposed to Target to Targeted status for JDK 19. Under the umbrella of Project Loom, this JEP proposes simplifying multithreaded programming by introducing a library to treat multiple tasks running on different threads as an atomic operation. As a result, it will streamline error handling and cancellation, improve reliability, and enhance observability. This is still an incubating API.

This allows developers to organize their concurrency code using the StructuredTaskScope class. It will treat a family of subtasks as a unit. The subtasks will be created on their own threads by forking them individually but then joined as a unit and possibly canceled as a unit; their exceptions or successful results will be aggregated and handled by the parent task. Let’s see an example:


Response handle() throws ExecutionException, InterruptedException 
   try (var scope = new StructuredTaskScope.ShutdownOnFailure()) 
       Future<String> user = scope.fork(() -> findUser());
       Future<Integer> order = scope.fork(() -> fetchOrder());

       scope.join();          // Join both forks
       scope.throwIfFailed(); // ... and propagate errors

       // Here, both forks have succeeded, so compose their results
       return new Response(user.resultNow(), order.resultNow());
   


The above handle() method represents a task in a server application. It handles an incoming request by creating two subtasks. Like ExecutorService.submit(), StructuredTaskScope.fork() takes a Callable and returns a Future. Unlike ExecutorServicethe returned Future is not joined via Future.get(). This API runs on top of JEP 425, Virtual Threads (Preview), also targeted for JDK 19.

The examples above use the StructuredTaskScope API, so to run them on JDK 19, a developer must add the jdk.incubator.concurrent module, as well as enable preview features to use virtual threads:

Compile the above code as shown in the following command:

javac --release 19 --enable-preview --add-modules jdk.incubator.concurrent Main.java

The same flag is also required to run the program:

java --enable-preview --add-modules jdk.incubator.concurrent Main;

However, one can directly run this using the source code launcher. In that case, the command line would be:

java --source 19 --enable-preview --add-modules jdk.incubator.concurrent Main.java

The jshell option is also available, but requires enabling the preview feature as well:

jshell --enable-preview --add-modules jdk.incubator.concurrent

The benefits structured concurrency brings are numerous. It creates a child-parent relationship between the invoker method and its subtasks. For instance, from the example above, the handle() task is a parent and its subtasks, findUser() and fetchOrder(), are children. As a result, the whole block of code becomes atomic. It ensures observability by demonstrating the task hierarchy in the thread dump. It also enables short-circuiting in error handling. If one of the sub-tasks fails, the other tasks will be canceled if not completed. If the parent task’s thread is interrupted before or during the call to join(), both forks will be automatically canceled when the scope exits. These bring clarity to the structure of the concurrent code, and the developer can now reason and follow the code as if they read through as if they are running in a single-threaded environment.

In the early

Read More

Best running gear: top gadgets to keep you motivated | Gadgets

Running is a great way to keep fit this summer and needs a little more than some trainers and a pavement or a park. But even the most enthusiastic of us need some way to keep motivated for regular exercise when the couch, TV or sun lounger looks inviting.

These gadgets can help: from music on the go to the social power of Strava, they make pounding the streets a little more interesting.

Music

A woman running with a phone in an armband and earphones.
Strapping your phone to your bicep in an armband helps keep it secure and out of the way when you run. Photograph: Cultura Creative (RF)/Alamy

Music or podcasts can help you eat up the miles with a bit of entertainment, but holding your phone while you run is not a comfortable way to do things.

Armband phone pockets are one solution. Strapped to your bicep with Velcro and a clear pouch, they let you work your phone and listen to music. They cost about £6-10 and come in various sizes. Or you can use an old MP3 player such as an iPod Shuffle if you still have one around.

Better yet, switch to a wearable music player with a running or smartwatch. Most good smartwatches, including the Apple Watch, Samsung Galaxy Watch 4 and others, can store music offline for playback straight to a set of Bluetooth headphones.

The Spotify app showing a running playlist on an Apple Watch.
Spotify and other music apps on smartwatches such as the Apple Watch can play music straight to a set of Bluetooth earphones without your phone. Photograph: Samuel Gibbs/The Guardian

If you don’t already have a smartwatch and want something for running, there are many different options. One of my favorites is the Garmin 245 Music, which offers excellent tracking, can store hours of music offline from Spotify, Deezer or others, and can be picked up for about £200.

While you can run with almost any headphones, including AirPods or large over-ear sets, there are models that are better designed for running. I recommend Bluetooth sets that don’t block out the world, allowing you to remain aware of your surroundings.

Shokz OpenRun Pro

A pair of Shokz OpenRun Pro headphones sitting on their nylon case.
Bone conduction headphones sit over your ears and vibrate your skull to transmit sound waves to your inner ear, bypassing your ear drum. Photograph: Samuel Gibbs/The Guardian

Bone conduction headphones send sound waves through your skull instead of your ear drum, making the music sound like it is coming from inside your head while maintaining your awareness of the outside world. Shokz makes some of the best, with lightweight, comfortable designs, long battery life and easy-to-reach onboard controls for playback and volume. They are the only headphones approved by England Athletics for races, too.

The latest £160 OpenRun Pro last up to 10 hours between charges, can Bluetooth pair to two devices at once, weigh only 29g and are IP55 water-resistant so you can safely sweat all over them. They sound good, with more bass than previous models, but bone conduction technology can’t match regular earbuds for low notes. The older £130 OpenRun are similar,

Read More

Quantum computer programming for dummies

Quantum computer programming for dummies

A new guide to programming quantum algorithms walks programmers through every step, from theory to implementing the algorithms on IBM’s publicly available 5-qubit ibmqx4 quantum computer and others. Credit: Dreamtime

For would-be quantum programmers scratching their heads over how to jump into the game as quantum computers proliferate and become publicly accessible, a new beginner’s guide provides a thorough introduction to quantum algorithms and their implementation on existing hardware.

“Writing quantum algorithms is radically different from writing classical computing programs and requires some understanding of quantum principles and the mathematics behind them,” said Andrey Y. Lokhov, a scientist at Los Alamos National Laboratory and lead author of the recently published guide in ACM Transactions on Quantum Computing. “Our guide helps quantum programmers get started in the field, which is bound to grow as more and more quantum computers with more and more qubits become commonplace.”

In succinct, stand-alone sections, the guide surveys 20 quantum algorithms—including famous, foundational quantum algorithms, such as Grover’s Algorithm for database searching and much more, and Shor’s Algorithm for factoring integers. Making the real-world connection, the guide then walks programmers through implementing the algorithms on IBM’s publicly available 5-qubit IBMQX4 quantum computer and others. In each case, the authors discuss the results of the implementation and explain the differences between the simulator and the actual hardware runs.

“This article was the result of a rapid-response effort by the Information Science and Technology Institute at Los Alamos, where about 20 Lab staff members self-selected to learn about and implement a standard quantum algorithm on the IBM Q quantum system,” said Stephan Eidenbenz, a senior quantum computing scientist at Los Alamos, a coauthor of the article and director of ISTI when work on it began.

The goal was to prepare the Los Alamos workforce for the quantum era by guiding those staff members with little or no quantum computing experience all the way through the implementation of a quantum algorithm on a real-life quantum computer, Eidenbenz said.

These staff members, in addition to a few students and well-established quantum experts, make up the long author list of this “crowd-sourced” overview article that has already been heavily cited, Eidenbenz said.

The first section of the guide covers the basics of quantum computer programming, explaining qubits and qubit systems, fundamental quantum concepts of superposition and entanglement and quantum measurements before tackling the deeper material of unitary transformations and gates, quantum circuits and quantum algorithms.

The section on the IBM quantum computer covers the set of gates available for algorithms, the actual physical gates implemented, how the qubits are connected and the sources of noise, or errors.

Another section looks at the various types of quantum algorithms. From there, the guide dives into the 20 selected algorithms, with a problem definition, description and steps for implementing each one on the IBM or, in a few cases, other computers.

Extensive references at the end of the guide will help interested readers go deeper in their explorations of quantum algorithms.


Developing the

Read More

5 New Gadgets to Keep on Your Radar

For more of the latest and greatest product releases, check out our full collection of the best new gear.


This week, Google rolled out an update to Google Maps so that the app now factors in the cost of tolls during your journey. Adobe announced plans to launch a free version of Photoshop. Apple won the rights to broadcast every MLS soccer game come the 2023 season on the Apple TV app. And Internet Explorer officially went kaput.

A bunch of cool new gadgets were announced as well. Here’s what you need to know.

Sony NW-WM1ZM2 and NW-WM1AM2

sony

Sony

Sony added two portable hi-fi players to its Walkman line, the Sony NW-WM1ZM2 ($3,700) and the Sony NW-WM1AM2 ($1,400), both of which are designed for music lovers with large music libraries or subscribe to the one of lossless music services. The biggest upgrade is that both the NW-WM1ZM2 and the NW-WM1AM2 run on Android 11, rather than Sony’s own operating system; this allows them to be more future-proof (Android updates are way more consistent), but more importantly gives them access to all the latest lossless streaming services including Apple Music, Deezer, Amazon Music, Tidal and Qobuz.

(The main difference between the Sony NW-WM1ZM2 and the Sony NW-WM1AM2 is that the former costs more because it has a gold-plated body and comes with double the on-board storage.)

Prices: $1,400 — $3,700

LEARN MORE

Fujifilm Instax Mini Link 2

fujifilm

Fujifilm

Fujifilm’s newest portable printer, the Instax Mini Link 2 ($100), connects to your smartphone and allows you to print any photo from your photo library; it basically allows you to use your smartphone just like one of the company’s separate instant film cameras. The Instax Mini Link 2 is a new-and-improved version of Fujifilm’s 2019-released Instax Mini Link, with the major upgrade being that it has a new “rich” printing mode that adds extra color saturation and highlights to the print to make it really “pop.”

Prices: $100

LEARN MORE

Ikea Obegränsad Record Player

ikea

Ikea

Ikea announced plans to release a record player, called the Obegränsad, this coming fall. Designed in tandem with the famous house music group Swedish House Mafia, the record player will come with a built-in pre-amplifier for easy connecting to a powered speaker or sound system. There’s no word on pricing yet.

Prices: TBD

LEARN MORE

DJI RS3 and RS3 Pro

dji

DJI

DJI announced the RS3 and RS3 Pro, which are its newest gimbals that are designed for mirrorless and cinema cameras, respectively. The main upgrade over their predecessors, mainly the 2020-released RSC2, is the new gimbals have an updated and improved automatic locking system so you don’t need to spend as much time balancing the camera during setup. They also come with a larger touchscreen display and support for a Bluetooth shutter button.

Prices: $549+

LEARN MORE

Kasa Smart WiFi Plug Mini

style

TP-Link

TP-Link’s newest smart plug, the Kasa Smart WiFi Plug Mini, is unique because it’s the company’s first (and one of the few out there )

Read More

The Learning Sciences Meet The Learning Health System

In asexual copy all the genes within the offspring come from one father or mother. In sexual reproduction half of the genes come from each parent.

Educational Instruments

Food provides materials and power for organisms to carry out the fundamental capabilities of life and to develop. Green plants and some micro organism are ready to use vitality from the Sun to generate advanced meals molecules. Animals acquire power by breaking down complex Home Improvement News meals molecules and are finally dependent on inexperienced vegetation as their supply of vitality. In any ecosystem there may be competitors amongst species for the power sources and supplies they should reside and reproduce.

Science Lecturers Acknowledge That Evolution And Local Weather Change Are Widely Misunderstood Or Rejected In Lots Of Locations

While this international health disaster continues to evolve, it can be helpful to look to previous pandemics to better perceive how to reply right now. In Ghana, we support 30 oncology nurse scholarships at the Ghana College of Nurses and Midwives. This initiative, made possible by way of the Roche Recherche en Afrique Foundation, will more than triple the number of oncology nurses in Ghana. Through the same foundation, we support AO Alliance to coach 20 orthopedic technicians to assist better outcomes for trauma injury patients. A scientific concept or model representing relationships between variables of a natural phenomenon should match the observations out there on the time and result in predictions that may be examined. Any theory or mannequin is provisional and subject to revision within the gentle of latest data despite the fact that it could have led to predictions in accord with data up to now.

A group from Rutgers University is analyzing the NAEP data to attempt to determine the reasons for the drop in math scores. One of the biggest cross-nationwide tests is the Programme for International Student Assessment , which each and every three years measures reading capability, math and science literacy and other key abilities amongst 15-12 months-olds in dozens of developed and developing countries. The most recent PISA outcomes, from 2015, placed the U.S. an unimpressive thirty eighth out of seventy one international locations in math and 24th in science.

If you were born in the twenty first century, iPads and Chromebooks in class are a well-recognized sight. Wilkens advised ZDNet that the method and follow of teaching K-12 laptop science are shifting.

education and science

Educators are shifting to a teaching model that comes with laptop science in each educational subject. Preparatory Department for Foreigners How to learn Russian and enter university. Another lengthy-working testing effort is the National Assessment of Educational Progress, a project of the federal Education Department. In the latest NAEP outcomes, from 2015, common math scores for fourth- and eighth-graders fell for the first time since 1990.

Since then, they have performed a serious role in shaping education and proceed to take action, according to Todd Cherner. But for older Millennials and earlier generations, computers at school often have been desktop machines. If … Read More