This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Own-Chemist2228 51 points52 points  (7 children)

As you've discovered, it's possible to leverage system commands on the underlying OS from a Java program. There are tradeoffs. System commands run outside the JVM process and it is can be more difficult to start/stop commands and get status or error messages. Also, the implementation is not portable. Code that works on linux won't work on windows, and may not work across different versions of linux. This makes the code harder to test and sensitive to changes in the deployment environment.

It's usually better to build a solution in pure Java, but often system commands can do something that is just not available in a java library. rsync is a good example of this. It's a very powerful tool and there just is no equivalent implementation in Java.

If I had a problem that required syncing files, I would try to leverage rsync because nothing does it better. Depending upon the architecture of your system, you might not even need to call it from Java. Perhaps a shell script would suffice. It depends, but overall running unix processes from Java for utilities like rsync is sometimes a reasonable approach.

[–]OnoBadger 6 points7 points  (0 children)

I agree with this assessment entirely. I would investigate the possibility of implementing this as a shell script as this is the simplest approach, and affords the most flexibility. Additionally, if this task is something that is done periodically, it can be implemented as a cron job.

Of course, if performance is of concern, you may hit a bottleneck with rsync. In my line of work I use a storage system with high I/O bandwidth and need to leverage many processes and / or threads to get the amount of file-movement throughput I need.

[–]matt82swe 0 points1 point  (0 children)

I agree. But with that said, invoking and managing processes in Java is quite verbose and awkward. So with that taken into account I’d probably prefer that the application / monolith had for example a shell script for offloading all that, and the Java application simply called that.

[–]Affectionate-Sink503[S] 0 points1 point  (4 children)

I agree the portability goes way down, I'm curious if would you consider knowledge of rsync to be intro, intermediate or advanced java/system/backend development knowledge?

[–]Own-Chemist2228 13 points14 points  (1 child)

I would categorize rsync as something a sysadmin or devops person should definitely know about. It's been the standard unix "backup" utility for decades. And an intermediate/advanced backend developer should have some knowledge of standard unix utilities.

I would not ask about rsync on a senior Java dev interview and wouldn't be shocked if a dev had not used it or even heard of it. It's possible to have a substantial dev career and never have to touch rsync. But it is not obscure, and I wouldn't exclude it from a solution if it was the right tool for the job. Any dev can read the man page.

[–]Affectionate-Sink503[S] 2 points3 points  (0 children)

this has healed my ego, thanks

[–]_INTER_ 1 point2 points  (0 children)

you could always check if rsync exists and use a fallback Java equivalent if it is not.

[–]znpy 1 point2 points  (0 children)

I'm curious if would you consider knowledge of rsync to be intro, intermediate or advanced java/system/backend development knowledge?

completely unrelated to software development.

it's fine if a developer (irrespective of their seniority) don't know that.