Jump to content

make results dynamic in java

Featured Replies

I am creating  console application of top command (Linux) through java, but the results are only given for just  the instant   you run the program, I don't know how to delay or refesh  the results with time to be like in Linux for the top command (the result appears continuously and dynamic like in linux )

33 minutes ago, jonas garden said:

I am creating  console application of top command (Linux) through java, but the results are only given for just  the instant   you run the program, I don't know how to delay or refesh  the results with time to be like in Linux for the top command (the result appears continuously and dynamic like in linux )

It's hard to pinpoint your problem with the facts given but as a general approach you may have a look exiting code. The github project jvmtop seems to have a goal similar to yours; it may not be very active but could provide some hints about how to proceed. The method run(ConsoleView view) in class JvmTop.java and the output implementation in VMDetailView.java may be reasonable points to start.

 

Note & Disclaimer: I am not a participant in the project and I have not used the code or done anything further check the quality of the code in JvmTop 

There are special ANSI codes to control cursor position and clearing terminal, storing and restoring cursor position etc etc.

https://en.m.wikipedia.org/wiki/ANSI_escape_code

Write example code which is using them to check whether it is what you want.

It is independent from used computer language.

 

Edited by Sensei

Iirc (this may not be true but it is for most dynamic console commands) top uses ncurses which is a TUI library.  It’s fairly easy to do this ncurses though my only experience with it is in C not Java, you may want to see if there are binding for that.  The old school way is to simply redraw the entire console with only the characters you want changed changed.  Normally you’d check how tall the current console is and ‘\n’ your way to a clear screen before redrawing, but you can use the clear command if you want (most languages have a system library that lets you call commands programmatically.)

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.