Design patterns for pre initialize data for one task [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 4 years ago.
Improve this question
I have working on developing scheduling application as a start up and application take some time to complete. during the scheduling process I cannot use service calls to load data, because it will reduce the performance. It may cause to terminate the process if data access failed.
So I need to load required data before starting the scheduling process and discard that data after completing the schedule. This is some kind of caching but it doesn't need all the features in caching like check for expiries, discard expiries update new changes etc. Need to load once a month only for the scheduling.
So can somebody tell me what is the best design pattern to handle that situation. Thanks

Well that's a place for Prototype pattern, but you should also consider using some caching framework and just disable all fancy features like expiration, pinning, etc.

In the test automation patterns such
need to load required data before starting the scheduling process and discard that data after completing the schedule.
is called fixtures. So what you need can be achieved with setUp() and tearDown() functionality. Generally a Setup Decorator will do just fine. It'll "bracket" the execution of the entire scheduling process with a set of matching setUp and tearDown "book ends".

Related

Deleting files in the background service [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I need to delete files in the background service after a certain time, is it possible to implement this and in what way?
You can try WorkManager. It will delete your file...
Question is pretty vague. Please be specific on which OS you want to this, any specific technology, particular environment... queue of questions on your questions i so endless.
Though to answer at high level:
Solution 1: If windows / Linux, you can write a batch / shell script which you can mark into Windows scheduler / Linux cron job. Batch will have all logic to what to delete from which path, any specific file or starting with etc. scheduler / cron job will decide at what time you want to do this. For this timeline you need to check syntax and for both OS its different. Simple search and you will get everything.
Solution 2: If you want o do it by code, you can write a Spring scheduler code (this can be in any language, but as Java developer, I will prefer this) which will interact with file system and perform file deletion for you after particular interval. For this you may need an application server to deploy.
If application server is available on machine then this will be easy job for you, or else easiest thing to do is Solution 1.

Plan for portable Java CRUD application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
The target computers have either MySQL or SQL Server running on.
We get JDBC drivers for MySQL and SQL Server in our project.
When the users start the application they select which of the 2 databases to use.
One thread handles the GUI CRUD buttons and another handles the CRUD logic.
We get everything into .jar file(including the JDBC drivers) and convert it to .exe to be executed on the target computers.
Is this plan correct or it doesn't work this way?
Just include both the drivers, that's totally ok. As long as you only load one there definitely won't be any problems.
You may implement a simple detection of the databases at their standard paths / check if it is already running on the default port. If there's only one database avaiable, just work with that.
If you use Swing, there's the SwingWorker class to encapsulate (long running) CRUD operations. The gui is managed by the main thread / EDT, there's no need to exactly create 2 threads, if you're doing it right. (Although internally there will be multiple threads, but I'm talking about explicit Thread creation here.) Otherwise you would produce them busy wait scenario which could be really cpu consuming.
You can produce runnable jar files, which can be double clicked and executed on most systems, there's no need to convert it to exe-files.

What is the best wait command to use in Selenium [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 8 years ago.
Improve this question
I'm in the process of building an automated test pack in Selenium using Eclipse and Java. What I'm finding as I am going along is that sometimes certain actions can take longer than they did previously. So, whilst I am aware that I need to implement some kind of wait command I was wondering what would be the most effective one to use? Essentially, what I want is for the web page to wait for X seconds before it returns an error in the console.
Also, based on peoples past experience, what would be the best way of implementing this? I'm thinking that I create some kind of 'wait commands' class, which will have a series of methods that can be used depending on the scenario. Is this the right kind of approach?
selenium has matured inbuilt wait mechanism.
It has implicit wait, which means when you navigate to a new page, it wait until the entire page loads, before doing any action on the page.
In places where Ajax is used, the above may not be of help, hence we have to use explicit wait to ensure ajax request is complete. ex:
(new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
Check out the following link, for more details
http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits

Android Design Best Practice [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 am in the process of designing my first Android application and have a best practices/design question. So not necessarily looking for code, but for someone to lead me in the right direction as far as research goes.
I am looking to have an application where a user kicks off a timer. When that timer has expired, the application will run some code. I need the timer to continue to run even when the user closes the application and/or reboots the phone. So even if the phone dies, once it is charged and turned back on I need my application to kick off and recognize the timer has expired and run some code or continue counting down (essentially checking to see if a particular date and time has been reached). In addition, I want the user to be able to re-launch the application and end the timer pre-maturely if desired.
I thought I was on the right track by creating a local service in a seperate process but further research shows that may not be best practice and to look into alarm manager with broadcast. So my question to the masses...what route should I be tacking to achieve my goal?
Thoughts/Suggestions? Thanks in advance!!!
I thought I was on the right track by creating a local service in a seperate process
That is an anti-pattern (everlasting service) on top of an anti-pattern (separate process).
what route should I be tacking to achieve my goal?
Use AlarmManager, plus a BOOT_COMPLETED BroadcastReceiver. The BroadcastReceiver can detect missed events, plus set up a fresh AlarmManager schedule.

What is the prefered way of updating 'created' and 'updated' columns? Via triggers or via the software? [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 6 years ago.
Improve this question
I was wondering what people prefer when fields like 'created' and 'modified' have to be changed? Is it prefered to do this in the application code or use triggers for that??
Both are valid, but my experience is that it's more common to do it in code. I tend to put it in the application code.
Often you want to be able to cross-reference these timestamps with various logging information. Doing it in code ensures that the timestamps line up. Otherwise, you add an extra maintenance load to always ensure that the system time on your db-servers and app-servers are in sync
Logic today tends to be more in the application than in the database. Stored procedures and the likes are less and less utilized, especially in systems being built from scratch. Therefore, less and less notice is taken of the database so putting logic in triggers tend to get forgotten over time and it makes it harder to debug your application as logic will pass across process (and technology) boundaries.
Sometimes triggers don't fire. Many people will claim that they are fool-proof, but I've seen them fail more than once. And it has forever tainted my opinion of them.
Proper design and usage of AOP and framework support will let you do this fairly unobtrusively and with minimal copy/paste boiler-plate code.
Doing it via triggers would have been preferred if every database supported triggers on Insert and Update. But that is not the case with all the databases. Your Java code should be database agnostic as much as possible and code should not assume dependency on particular database(s) hence it is better to have some layer/interceptor between your application code and database to do this for you. That way you can avoid repetitive code and keep business logic clean from these update calls.

Categories

Resources