hw1: Ex5 tested

This commit is contained in:
Claudio Maggioni 2019-10-21 10:45:09 +02:00
parent ae127b3240
commit 67dbbe3f64
3 changed files with 18 additions and 1 deletions

2
hw1/.gitignore vendored
View File

@ -1,3 +1,5 @@
**/target/**/*
*.pdf
## Core latex/pdflatex auxiliary files:

View File

@ -4,13 +4,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- run with: mvn clean install exec:java -->
<groupId>ch.usi.inf.pf3.hw1</groupId>
<artifactId>ex5</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<finalName>${artifactId}</finalName>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -31,6 +33,14 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>reentrantrwlock.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -31,6 +31,7 @@ public class MovieCatalog {
int length;
rLock.lock();
length = movies.size();
System.out.println("The movies catalog size is: " + length);
rLock.unlock();
return length;
}
@ -45,6 +46,7 @@ public class MovieCatalog {
Movie m;
rLock.lock();
m = movies.get(title);
System.out.println("Getting movie: " + m.getTitle());
rLock.unlock();
return m;
}
@ -57,6 +59,7 @@ public class MovieCatalog {
List<String> titles;
rLock.lock();
titles = new ArrayList<>(movies.keySet());
System.out.println("Getting title list of length " + titles.size());
rLock.unlock();
return titles;
}
@ -74,6 +77,7 @@ public class MovieCatalog {
it.next();
}
m = it.next();
System.out.println("Getting random movie: " + m.getTitle());
rLock.unlock();
return m;
}
@ -85,6 +89,7 @@ public class MovieCatalog {
public void addMovie(Movie movie) {
wLock.lock();
movies.put(movie.getTitle(), movie);
System.out.println("Putting movie: " + movie.getTitle());
wLock.unlock();
}
}