Skip to content

Commit cc74888

Browse files
committed
Merge branch 'master' into BAEL-1344
2 parents 99ae59b + 408cf84 commit cc74888

35 files changed

Lines changed: 454 additions & 149 deletions

File tree

‎algorithms/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
- [Bubble Sort in Java](http://www.baeldung.com/java-bubble-sort)
1515
- [Introduction to JGraphT](http://www.baeldung.com/jgrapht)
1616
- [Introduction to Minimax Algorithm](http://www.baeldung.com/java-minimax-algorithm)
17+
- [How to Calculate Levenshtein Distance in Java?](http://www.baeldung.com/java-levenshtein-distance)

‎apache-spark/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Relevant articles
2+
3+
- [Introduction to Apache Spark](http://www.baeldung.com/apache-spark)

‎cas/cas-secured-app/pom.xml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@
6565
<groupId>org.springframework.boot</groupId>
6666
<artifactId>spring-boot-maven-plugin</artifactId>
6767
</plugin>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-surefire-plugin</artifactId>
71+
<version>${maven-surefire-plugin.version}</version>
72+
<configuration>
73+
<forkCount>3</forkCount>
74+
<reuseForks>true</reuseForks>
75+
<excludes>
76+
<exclude>**/*IntegrationTest.java</exclude>
77+
<exclude>**/*LongRunningUnitTest.java</exclude>
78+
<exclude>**/*ManualTest.java</exclude>
79+
<exclude>**/JdbcTest.java</exclude>
80+
<exclude>**/*LiveTest.java</exclude>
81+
</excludes>
82+
83+
</configuration>
84+
</plugin>
85+
6886
</plugins>
6987
</build>
7088

@@ -107,4 +125,5 @@
107125
</pluginRepositories>
108126

109127

128+
110129
</project>

cas/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationTests.java renamed to cas/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredAppApplicationIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@RunWith(SpringRunner.class)
99
@SpringBootTest
10-
public class CasSecuredAppApplicationTests {
10+
public class CasSecuredAppApplicationIntegrationTest {
1111

1212
@Test
1313
public void contextLoads() {

‎core-java-concurrency/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@
3030
- [Guide to Volatile Keyword in Java](http://www.baeldung.com/java-volatile)
3131
- [Overview of the java.util.concurrent](http://www.baeldung.com/java-util-concurrent)
3232
- [Semaphores in Java](http://www.baeldung.com/java-semaphore)
33+
- [Daemon Threads in Java](http://www.baeldung.com/java-daemon-thread)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung.concurrent.stopping;
2+
3+
import java.util.concurrent.atomic.AtomicBoolean;
4+
5+
public class ControlSubThread implements Runnable {
6+
7+
private Thread worker;
8+
private int interval = 100;
9+
private AtomicBoolean running = new AtomicBoolean(false);
10+
private AtomicBoolean stopped = new AtomicBoolean(true);
11+
12+
13+
public ControlSubThread(int sleepInterval) {
14+
interval = sleepInterval;
15+
}
16+
17+
public void start() {
18+
worker = new Thread(this);
19+
worker.start();
20+
}
21+
22+
public void stop() {
23+
running.set(false);
24+
}
25+
26+
public void interrupt() {
27+
running.set(false);
28+
worker.interrupt();
29+
}
30+
31+
boolean isRunning() {
32+
return running.get();
33+
}
34+
35+
boolean isStopped() {
36+
return stopped.get();
37+
}
38+
39+
public void run() {
40+
running.set(true);
41+
stopped.set(false);
42+
while (running.get()) {
43+
try {
44+
Thread.sleep(interval);
45+
} catch (InterruptedException e) {
46+
// no-op, just loop again
47+
}
48+
// do something
49+
}
50+
stopped.set(true);
51+
}
52+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.concurrent.stopping;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertFalse;
6+
import static org.junit.Assert.assertTrue;
7+
8+
public class StopThreadTest {
9+
10+
@Test
11+
public void whenStoppedThreadIsStopped() throws InterruptedException {
12+
13+
int interval = 100;
14+
15+
ControlSubThread controlSubThread = new ControlSubThread(interval);
16+
controlSubThread.start();
17+
18+
// Give things a chance to get set up
19+
Thread.sleep(interval);
20+
assertTrue(controlSubThread.isRunning());
21+
assertFalse(controlSubThread.isStopped());
22+
23+
// Stop it and make sure the flags have been reversed
24+
controlSubThread.stop();
25+
Thread.sleep(interval);
26+
assertTrue(controlSubThread.isStopped());
27+
}
28+
29+
30+
@Test
31+
public void whenInterruptedThreadIsStopped() throws InterruptedException {
32+
33+
int interval = 5000;
34+
35+
ControlSubThread controlSubThread = new ControlSubThread(interval);
36+
controlSubThread.start();
37+
38+
// Give things a chance to get set up
39+
Thread.sleep(100);
40+
assertTrue(controlSubThread.isRunning());
41+
assertFalse(controlSubThread.isStopped());
42+
43+
// Stop it and make sure the flags have been reversed
44+
controlSubThread.interrupt();
45+
46+
// Wait less than the time we would normally sleep, and make sure we exited.
47+
Thread.sleep(interval/10);
48+
assertTrue(controlSubThread.isStopped());
49+
}
50+
}

‎core-java/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,5 @@
115115
- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int)
116116
- [Proxy, Decorator, Adapter and Bridge Patterns](http://www.baeldung.com/java-structural-design-patterns)
117117
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
118-
118+
- [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static)
119+
- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array)

‎deeplearning4j/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
This is a sample project for the [deeplearning4j](https://deeplearning4j.org) library.
33

44
### Relevant Articles:
5-
- [A Guide to deeplearning4j](http://www.baeldung.com/a-guide-to-deeplearning4j/)
5+
- [A Guide to deeplearning4j](http://www.baeldung.com/deeplearning4j)

‎ejb/wildfly/widlfly-web/src/main/java/TestEJBServlet.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
2626
PrintWriter out = response.getWriter();
2727

2828
out.println("<html>");
29-
out.println("<head><title>Users</title></head>");
3029
out.println("<body>");
31-
out.println("<center><h1>List of users:</h1>");
32-
out.println("<table border=\"1\" align=\"center\" style=\"width:50%\">");
3330
for (User user : users) {
34-
out.println("<tr>");
35-
out.print("<td>" + user.getUsername() + "</td>");
36-
out.print("<td>" + user.getEmail() + "</td>");
37-
out.println("</tr>");
31+
out.print(user.getUsername());
32+
out.print(" " + user.getEmail() + " <br>");
3833
}
34+
out.println("</body>");
35+
out.println("</html>");
3936
}
4037

4138
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

0 commit comments

Comments
 (0)