Urgent.News

What's breaking now, across thousands of outlets.

Tech

Stop hand-writing cron: build and parse it in Java

Stop hand-writing cron: build and parse it in Java Quick, what does this fire? 0 0 18 ? * FRIL Last Friday of every month, 6 PM. You probably got the 6 PM part. The FRIL is the kind of thing you paste into a comment and hope nobody asks about later. I got tired of that guessing game, so I've been using cronsmith , a small Java library that lets you build a cron expression by describing it, parse…

Stop hand-writing cron expressions: build and parse them in Java. Building and parsing cron expressions in Java is a more reliable way to handle scheduling tasks. The CronBuilder class allows you to chain schedule specifications and generate the corresponding cron string. For example, every 5 seconds can be represented as */5 * * * * ?

0 30 9 * * ? every day at 09:30 0 10 15 ? * MON-FRI every weekday at 15:10. More complex schedules, such as the last Friday of the month at 18:00 or the 3rd Saturday of the month every 2 hours, can also be expressed using the CronBuilder. Parsing cron strings is just as easy using the CRON.parse() method, which normalizes the string and converts it into an object representing the schedule.

This eliminates the need to remember the various quirks of cron syntax, such as the meaning of L, #, and W, or whether 1 represents Sunday or Monday. The parsed schedule can then be converted into the appropriate format for different scheduling systems, such as Quartz, Spring, AWS EventBridge, or Unix. The CronBuilder library makes it simple to build and parse cron expressions, ensuring accurate scheduling without the guesswork associated with manual typing.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

The Complete Guide to SVG Icon Optimization for Web Performance

SVG icons have become the gold standard for modern web interfaces, prized for their crisp scalability, lightweight nature, and flexibility.

  • Optimizing SVGs reduces file sizes and improves web performance
  • Unoptimized SVGs cause slow rendering and compatibility issues
  • Tools like SVGO automate SVG optimization for web interfaces

More from Sunday 20 September →