Nothing special since morning was busy with some other work and a lot’s of telephonic conversation with my family so let’s start.

So let see my tasks

Tomorrow I should

  • Complete the benchmark problem of this

  • Run the file analyser in parallel

  • know about streaming Java Streamsand do this again in streaming

  • You can also take the bank’s csv analyser in here !! (Just saying that could be fun )

Link to original

Okay so I have to make the benchmark util which should be a middleware function

graph TD

Main -- query --> Middleware 
Middleware -- start the timer --> Function
Function -- returns value  --> Middleware 
Middleware -- gets the running time --> Main 


Now in python such things are called as decorators Let’s see things from the internet Nope no decorators but i can send a task to a another function !! cool and run it ..

In python

def benchmark(func):
    def wrapper():
        start = time.time()
        func()
        end = time.time()
        print("Time:", end - start)
    return wrapper
 
@benchmark
def my_logic():
    ...
 
my_logic()
 

**So How to Do this Now

Every One of my class implements a parent class called let's say Runnable 
Runnable has method run 
and i can 
public interface Runnable {
	void run();
}

**The Benchmark Util

public class BenchmarkMiddleware implements Runnable {
	private  Runnable task 
 
	public setTask(Runnable task ){
		this.task = task 
	}
	
	@override
	public void run() {
	    long start = System.nanoTime();
	    task.run(); 
	    long end = System.nanoTime();
	    System.out.println("Time: " + (end - start) + " ns");
    }
}
 

**Now lets do the function part

 
public class FileAnalyser implements Runnable {
	@override 
	public void run (){
		// Add the whole logic here 
	}
	
}
 

**Now the main function

  • Rather than directly calling the fileAnalyser we will call the main
 
public class Main {
    public static void main(String[] args) {
        Runnable file_analyse_tsk = new FileAnalyser();           
        Runnable benchmarked = new BencharkMiddleware(file_analyse_tsk);  
        benchmarked.run();          
    }
}
 
 

Let’s implement this

The Code works

git commitId edc41432272d88f62a58eff3a729c036e3e2d521

Questions

Why @Override in FileAnalyzerTask?**

Because it implements Runnable, which defines run().
@Override tells the compiler you’re correctly overriding that method.

✅ Catches typos
✅ Improves readability

🔧 Optional, but best practice

“Why was @Override used in FileAnalyzerTask?”

What if i want inputs for this run method to work

Custom Functional Interface Java

Since Runnable.run() can’t take arguments, you pass inputs through the constructor.

✅ Example:

public class FileAnalyzerTask implements Runnable {
    private final String path;
 
    public FileAnalyzerTask(String path) {
        this.path = path;
    }
 
    @Override
    public void run() {
        System.out.println("Analyzing: " + path);
    }
}

Usage:

Runnable task = new FileAnalyzerTask("./files");
task.run();

✅ Clean
✅ Standard in Java
❌ You cannot change run() to take parameters.

  • How to make notes where you learn from websites and llm at the same time