Java Timer vs. Linux Cronjob [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm doing automation on data fetching using Java , which approach is better for task automation? Linux cronjob or Java Timer?
for example the tasks to execute hourly, first day of week, first day of month, thanks in advance.

If you need the application to be always running for some other reason, and the data fetching happen frequently, you can consider using java task.
If you will write an application just for this purpose, or it is an application you dont need to to be always open since its not perfoming other continuos action, i'd prefer a cronjob, so you can have the app out of the memory most time.
Also, notice cronjobs are very efficent, and fully trustable. So if the data frecuency is important and is not just related to some runtime features, i'd also prefer cronjob
This is just for mentioning a few high level scenarios, but as Keppil said, it could depend on many other aspects.

It might depend on what you want, but I will say that the times I have created automated tasks I have used cron jobs or Windows scheduled tasks. As Carlos stated, the Java program would have to be running in order to even be able to perform the operations. So if it is a production application and it dies, then the jobs can't be kicked off till it is brought back up again. Also, setting up a cron job is typically easier than writing a program.
On the other had, if it is a system that you do not have admin rights to and are unable to create or edit cron jobs but are able to kick off a Java program, the Java program might be easier.
Overall, the cron job seems to be the industry "best practice" (sorry for the buzz word), but, again, it might depend on your specific situation.

Related

How to fine control multiple threads in a Java Application? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am writing a Java Application that aims to get and persist messages in real time. Beyond that, my application should care about several non-functional requirements like lineage control, transaction control, security, logging, monitoring, and so on.
Each feature is defined as a module and will be controlled within a thread concurring to my hardware resources (disk, memory, CPU, and GPU). As consequence, each time my application evolves, my thread control should evolves too.
To deal with that I am creating a global ExecutorService to manage all threads in my application. Some of these threads are permanent and defined as daemon. My application also control multiple sources. Each one representing a set of all features described above, evolving arbitrarily.
Which are the best practices for that scenery? How to control multiple threads while some will be created and dropped arbitrarily (as daemon or not) and another ones will be executed regularly nested or not to another threads?
Generally, if you do not want to manage creation and disposal of threads, use a thread pool (you can create one with ExecutorService executorService = Executors.newFixedThreadPool(10);).
However, be careful of premature optimisation (i.e. spending effort "optimising" code, at the expense of readability/maintainability, often when the performance gain is irrelevant). General good practice is:
Write clean, readable code.
Run your code and see if you encounter performance issues
Profile your code (e.g. with JProfiler or JVisualVM) to identify performance issues
Refactor your code if there is a significant problem with the way it is.
Remember, in general, developer time is more valuable than CPU time. Obviously there are limits to this, but usually you are best served keeping your code clean and readable.
You can also use this process to tweak parameters (e.g. on a fixed thread pool, there are various thresholds that can be fine-tuned to improve performance).

Do JVMs create significant overhead in distributed/ parallel processing? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
If a distributed computing framework spins up nodes for running Java/ Scala operations then it has to include the JVM in every container. E.g. every Map and Reduce step spawns its own JVM.
How does the efficiency of this instantiation compare to spinning up containers for languages like Python? Is it a question of milliseconds, few seconds, 30 seconds? Does this cost add up in frameworks like Kubernetes where you need to spin up many containers?
I've heard that, much like Alpine Linux is just a few MB, there are stripped down JVMs, but still, there must be a cost. Yet, Scala is the first class citizen in Spark and MR is written in Java.
Linux container technology uses layered filesystems so bigger container images don't generally have a ton of runtime overhead, though you do have to download the image the first time it is used on a node which can potentially add up on truly massive clusters. In general this is not usually a thing to worry about, aside from the well known issues of most JVMs being a bit slow to start up. Spark, however, does not spin up a new container for every operation as you describe. It creates a set of executor containers (pods) which are used for the whole Spark execution run.

Design help to schedule file polling and api call [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
What is the best way to schedule a java program, after searching for some time we came across below 3 ways, which is the better of these three, is something that is getting us confused and if there is any better way please let us know.
One way 1:
Create a windows task scheduler service to execute a standalone java program to fetch file info and make webService call. Like this)
Second way 2:
Create a quartz scheduler service to execute a standalone java program to fetch file info and make webService call. Like this
Third way 3:
Use TimerTask(available in java.util package) to execute task in another class.like this
Please suggest which is better way to do it.
Solution 3, would be running throughout all time and will be in memory all time.
I feel you go with solution 2, as quartz gives you OS independence and allows have more options that windows scheduler.
Don't understand the down votes as you had done your research but asking for additional suggestion though.

What is the best strategy to make my demo Java library/framework stop working after 30 days on Linux? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Ok, it does not need to be something 100% secure. Something simple, that will cut 80% of people from using my demo library past 30 days and contact me.
The only thing I can think of is making my code save a file somewhere, with the date that the library started and after 30 days just exit displaying a message to contact for the full version. Of course, if the user finds out where this file is, all he has to do is delete it, so it would be nice if it could be in some kind of not so easy to find place (desktop or home directory would be silly I suppose).
Of course if he decompiles the code, he can easily turn that off, but again, I want some protection, even 50%, not 100%.
Target operating system is probably linux/unix, but I can also discover dynamically to make it work in any.
You don't mention the target operating system, so it is a little bit hard to answer the question. If your target is Windows, I would store the first start time in the Registry. Maybe this can help you.
I think your file strategy looks perfectly fine.
If you want to strengthen your scheme, you will have to contact a central service of some sort where you can detect if the same server tries to restart your evaluation time multiple times. The central server could i.e. sign a token with an expiry date that the library needs to run.
On the other hand, the more complicated this kind of schemes is, the more likely they are to fail at times and create problems for your legitimate users. You should consider this against the (probably very low) volume of users that would actively sabotage a more simple scheme.
PS: remember that in some environments multiple copies of different applications that uses your library may have to run simultaneously.

Running a resource-hungry application on the web [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've been writing some console applications in c++ for working with audio for a little while now and I'm interested in running them on a website. Most of my programs are quite resource-hungry, however, some with execution times of up to 5-10 min, reading and writing several gigabytes to and from disk, and requiring several gigabytes of memory. I've done a few simple php-mysql pages before, but nothing like this, so before i get my hopes up and dive into learning how to get an application running on a website, i figure i should ask a few questions:
Is it even feasible to run a program like this on the web? How would performance on a server compare to my PC?
Do web hosts typically allow a single user to use this kind of memory?
I realize c++ isn't usually the first choice for web programming, but since performance will be critical would it be better than Java?
I know nothing about this, so i'm just trying to get my expectations straight.
This is my opinion:
1 - The user of your web application is probably not going to wait 5-10 min for a response. You can focus on doing the hard-work on another process and your web app later shows the results to your user in some way.
2 - Yes, they allow, but that costs money. You can see Amazon EC2 and Digital Ocean (cheaper).
3 - The programming language in this case (C++ or Java) is not that important. Focus more on your problem, architecture, deferred tasks, batch processing, etc. That will really make a difference.
No, the programming language doesn't much matter. It used to be the case that java was slower than C++ i believe, but that gap has closed pretty much as compilers have improved. If you want to run your applications better, try to design them in such a way that they are very efficient. Looking into Time Complexity may help, if you haven't already done so. The better your time complexity, the faster your program.

Categories