Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 655651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:37:41+00:00 2026-05-13T22:37:41+00:00

I have a java JAR file that is triggered by a SQL server job.

  • 0

I have a java JAR file that is triggered by a SQL server job. It’s been running successfully for months. The process pulls in a structured flat file to a staging database then pushes that data into an XML file.

However yesterday the process was triggered twice at the same time. I can tell from a log file that gets created, it looks like the process ran twice simultaneously. This caused a lot of issues and the XML file that it kicked out was malformed and contained duplicate nodes etc.

My question is, is this a known issue with Java JVM’s spawning multiple instances of itself? Or should I be looking at sql server as the culprit? I’m looking into ‘socket locking’ or file locking to prevent multiple instances in the future.

This is the first instance of this issue that I’ve ever heard of.

More info:

The job is scheduled to run every minute.
The job triggers a .bat file that contains the java.exe – jar filename.jar

The java program runs, scans a directory for a file and then executes a loop to process if the file if it finds one. After it processes the file it runs another loop that kicks out XML messages.

I can provide code samples if that would help.

Thank you,

Kevin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:37:41+00:00Added an answer on May 13, 2026 at 10:37 pm

    It’s not a Java problem. If you want the app to run alone, no copies, you should use the shell script or the java app to make and remove a lock somewhere.

    You actually start multiple java’s by starting more than 1 batch job with the same command. Windows nor Java can now that’s not what you want. You could solve that by something like:

    public static void main(String [ ] args)
    {
       createLockIfNotExists();
       try {
           yourstuff;
       } finally {
         releaseLock();
       }
    }
    private static void createLockIfNotExists() throws MyLockAlreadyExists {
      // A bit tricky
      // check if LOCKFILE exists, if yes throw MyLockAlreadyExists
      // try to create LOCKFILE, can fail if at 1 ms earlier an other app created
      // that file, so an exception while creating also results in LockAlreadyExists
    }
    

    Are there good examples somewhere which handle this locking? Maybe in Apache Commons?

    Here seems to be a functioning example for Windows.

    You could also use the database to write your lock. Lock the locking table before you use it of course so no 2 processes write their lock at the same time, and afterwards read the lock record to check whether you actually got the lock. Something like pseudo code:

    SELECT * FROM lock_table;
    
    if locks.length > 0: someone else is running
    
    LOCK lock_table;
    INSERT INTO lock_table VALUES(my_pid);
    UNLOCK lock_table;
    
    SELECT pid FROM lock_table;
    
    if pids.length > 1: what happened?
    if pids[0] != my_pid: someone else got the lock 
    

    A bit more juice and you also add not only the PID but also a timestamp, and check whether that timestamp is stale (too old).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
If I have a jar file that is running, what is the best way
I have a C# class library that is running a jarFile string args=java -jar
Let's say that I have a jar file @ /usr/local/apps/app1/java/file.jar . I would like
I have a 3rd party JAR file that is compiled using Java 1.4. Is
I have a shell script that calls a java jar file and runs an
I have created jar file for my project. It is running successfully. There is
I have a java GUI jar file that i need to launch at my
I have created an executable Java .jar file. That is to say, I properly
I have written a standalone Java application that I've packaged into a jar file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.