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

  • Home
  • SEARCH
  • 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 7636187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:36:38+00:00 2026-05-31T07:36:38+00:00

i have two java files file1 and file2 as follows in package pak file1:

  • 0

i have two java files file1 and file2 as follows in package pak

file1:

package pak;
public  class file1 {
  public  static int x=432;

  public static void main(String[]  args){
    System.out.println("y is "+file2.y);
    while(x==432) {
      System.out.println("x is "+file1.x);
    }

  }
}

file 2:

package pak;
public  class file2 {
  public  static int y=46;
  public static void main(String[]  args){

   System.out.println("x is "+file1.x);
   ++file1.x;
   System.out.println("x is "+file1.x);

  }
}

i will run first file1 and it will be running and when i run file 2 from another shell it should increment x value and it should come out of loop in file 1
can some one pls help me ??????

  • 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-31T07:36:40+00:00Added an answer on May 31, 2026 at 7:36 am

    i will run killjava that kills the process in iostat.java and just before killing i need to perform one action

    You can do this with a shutdown hook.

    public static void main(String... args) throws InterruptedException {
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("Final stats");
            }
        }));
        System.out.println("PID " + ManagementFactory.getRuntimeMXBean().getName());
        while (true) {
            System.out.println("stats");
            Thread.sleep(2000);
        }
    }
    

    prints

    PID 29490@plus-dev-01
    stats
    stats
    stats
    stats
    stats
    Final stats
    

    The last line occurs after I run kill 29490 in another window.


    how will i do it for two different processes

    This is a complex answer with too many possible solution to mention. (Shared memory, JMS, RMI, signals, Sockets, IPC etc)

    Generally, this is done as a high level concept like “stop process” rather than “increment x” even if the result is the same.

    The problem is that as its an advanced topic, you would need to have a good understand of interprocess communication to understand the full answer.

    The simple solution is; don’t do it, find another way to do what you want.

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

Sidebar

Related Questions

I have two Java.io.File objects file1 and file2. I want to copy the contents
I have two Java classes: B, which extends another class A, as follows :
I have two Java class files: primegen and primecheck sitting in the same directory.
Have two folders with approx. 150 java property files. In a shell script, how
I have two java files in a directory, neither of them are in a
I have two files: Test.java Other.java I wanted to learn how to call the
I have two tab separated files (please see the examples below): File 1 Java
I have two java files. In the first I have my activity which starts
Consider this simple program. The program has two files: File Vehicle.java class Vehicle {
I'm learning Java am having trouble running an example program. I have two files:

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.