Skip to content
Permalink
Browse files
fix JENKINS-33219.
  • Loading branch information
Lucie Votypkova committed Sep 14, 2017
1 parent a13fd18 commit feda364b0b4dce45b7568ac5a2321940a8a618bb
@@ -74,5 +74,6 @@ public void onLoaded(){
DiskUsagePlugin plugin = Jenkins.getInstance().getPlugin(DiskUsagePlugin.class);
plugin.loadDiskUsageItemGroups();
DiskUsageUtil.getItemGroupAction(Jenkins.getInstance()).actualizeCashedData();

}
}
@@ -23,7 +23,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Message.RecipientType;
@@ -39,17 +39,32 @@
* @author Lucie Votypkova
*/
public class DiskUsageUtil {

private static DiskUsageProperty addProperty(final DiskUsageProperty property, final Job job) throws InterruptedException, ExecutionException, TimeoutException {
java.util.concurrent.Callable<DiskUsageProperty> call = new java.util.concurrent.Callable<DiskUsageProperty>() {
@Override
public DiskUsageProperty call() throws IOException {
job.addProperty(property);
return property;
}
};
//call it as future to not cause deadlock like JENKINS-33219"
Future<DiskUsageProperty> f = new FutureTask<DiskUsageProperty>(call);
DiskUsageProperty p = f.get(1, TimeUnit.SECONDS);
return p;
}

public static DiskUsageProperty addProperty(Item item) throws Exception {
DiskUsageProperty property = null;
if(item instanceof Job){
Job project = (Job) item;
final Job project = (Job) item;
property = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
if(property==null){
try {
property = new DiskUsageProperty();
project.addProperty(property);
} catch (IOException ex) {
final DiskUsageProperty newProperty = new DiskUsageProperty();
//better than synchronize call it as future with time out
addProperty(newProperty, project);
} catch (Exception ex) {
Logger.getLogger(DiskUsageItemListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
@@ -61,9 +76,10 @@ public static DiskUsageProperty addProperty(Item item) throws Exception {
DiskUsageProperty p = (DiskUsageProperty) project.getProperty(DiskUsageProperty.class);
if(p==null){
try {
p = new DiskUsageProperty();
project.addProperty(p);
} catch (IOException ex) {
DiskUsageProperty newProperty = new DiskUsageProperty();
//better than synchronize call it as future with time out
addProperty(newProperty, project);
} catch (Exception ex) {
Logger.getLogger(DiskUsageItemListener.class.getName()).log(Level.SEVERE, null, ex);
}
}

0 comments on commit feda364

Please sign in to comment.