Whilst I'm not overly familiar with the Java Sound API, a quick google search of Java Sound API provides a lot of information and code snippets.
You could use something like this
In order to start or stop the recording based on volume level, you could call the getLevel() method on the DataLine Object as a condition prior to line.Start() and line.stop() methods to check current volume from your mic.
i.e.
if(line.getLevel() < 0.3){
line.stop();
description of getLevel() method from javadocs
Obtains the current volume level for the line. This level is a measure of the signal's current amplitude,The range is from 0.0 (silence) to 1.0 (maximum possible amplitude for the sound waveform). The units measure linear amplitude, not decibels.