Site Search:

my Android phone's browser is freezing and crashing when visiting some pages

The indexing page of OCAJP makes my android browser freeze during scroll. This page has no javascript, (searching the post's HTML for "script" find nothing) , it has many style though.

This page even crashes the mobile browser, I can repeat the crashing.

I don't have global javascript and only have 3 blocks of global css.

What the hell is going on?

As I google around, looks like css is quite memory demanding.

One quick fix is to go to Template ->Mobile
Instead of using Default, use Simple instead.

The loading speed is faster on assessment-test-question-1.html , however the crash issue didn't go away though harder to reproduce, the index page and some other css heavy pages are still freezing sometimes (code blocks have lots of css).

When I use chrome on the same android phone, all the pages loaded fast and beautiful.
Firefox also loads all pages fine, a little bit less smooth than chrome.


Opera mini and Web Browser load decently on other pages, also freeze on This page, and later crashes.
I guess the javascript have memory leakage (need to tap twice in order to show the time left).
==========
http://xyzcode.blogspot.com/2016/02/oca-exam-1z0-808-breaks-down.html

<div style="background-color: white; font-family: arial, helvetica, sans-serif;">
<a href="https://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&amp;get_params=p_exam_id:1Z0-808" target="_blank">OCAJP (Oracle Certified Associate Java Programmer)</a>&nbsp;is prerequisite for&nbsp;<a href="http://xyzcode.blogspot.com/2016/07/ocp-exam-1z0-809-breaks-down.html" target="_blank">OCPJP (Oracle Certified Professional Java Programmer)</a> and beyond. So, in plain english, OCAJP is unavoidable. You can take <a href="https://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&amp;get_params=p_exam_id:1Z0-808" target="_blank">1Z0 - 808</a> exam to obtain OCAJP.<br />
<br />
OCAJP Exam changes year by year. It generally took 150 minutes, there are around 80 multiple choice questions, the pass rate is from 60% to 80%. <a href="http://xyzcode.blogspot.com/2016/02/sample-ocajp-questions.html" target="_blank">OCAJP questions</a> could be tricky, though they are basics.<br />
<br />
When I took the test, there are 77 questions, the pass rate is 65%. The first 10 questions are comparably longer/calculation extensive than the later ones. I used to do 60 questions simulation tests, the real test questions are longer and the time is tighter during the test. It worth over-preparing and you have to digest code (watching for compilation error) fast during real test, which is why the test cost $245.<br />
<br />
This free OCAJP study materials follows the break down list of OCAJP <a href="http://xyzcode.blogspot.com/2016/02/java-setup.html" target="_blank">java 8</a>, also called <a href="https://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&amp;get_params=p_exam_id:1Z0-808" target="_blank">OCA Exam 1Z0 - 808</a>.<br />
<br />
Whenever you need to learn more about a OCAJP and OCPJP keyword, use the Site Search at the upper left corner.<br />
<br />
Good luck with your OCAJP and OCPJP tests.<br />
<br />
<div>
<div style="font-family: Times;">
<h2>
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;">OCAJP</span></span></h2>
<div>
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;"><br /></span></span></div>
<h3>
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;">Simulation Tests</span></span></h3>
</div>
<div style="font-family: Times;">
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;">&nbsp; &nbsp; &nbsp;<a href="http://xyzcode.blogspot.com/2016/07/self-assessment-questions-for-ocajp.html" target="_blank">Self Assessment questions</a></span></span><br />
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;">&nbsp; &nbsp; &nbsp;</span></span><br />
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;">&nbsp; &nbsp; &nbsp;<a href="http://xyzcode.blogspot.com/2016/06/simulation-test-1-80-question-set-answer.html" target="_blank">Simulation Test 1 -- 80 question set</a></span></span><br />
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><br /></span>
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;">&nbsp; &nbsp; &nbsp;<a href="http://xyzcode.blogspot.com/2016/06/simulation-test-2-80-question-set-answer.html">Simulation Test 2 -- 80 question set</a></span><br />
<br />
&nbsp; &nbsp; &nbsp;<a href="http://xyzcode.blogspot.com/2016/06/ocajp-flash-cards.html">OCAJP flash cards</a><br />
<br />
&nbsp; &nbsp; &nbsp;<a href="http://xyzcode.blogspot.com/2016/07/flash-card-list-1.html" target="_blank">Quick Quiz, list 1</a><br />
<br />
&nbsp; &nbsp; &nbsp;<a href="http://xyzcode.blogspot.com/2016/07/flash-card-list-2.html" target="_blank">Quick Quiz, list&nbsp;2</a></div>
</div>
<div style="font-weight: bold;">
<strong><br /></strong></div>
<div style="font-weight: bold;">
<h3>
<strong>Java Basics&nbsp;</strong></h3>
</div>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/define-scope-of-variables.html" target="_blank">Define the scope of variables</a>&nbsp;</li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/define-structure-of-java-class.html" target="_blank">Define the structure of a Java class</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/create-executable-java-applications.html">Create executable Java applications with a main method; run a Java program from the command line; including console output.</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/import-other-java-packages-to-make-them.html" target="_blank">Import other Java packages to make them accessible in your code</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/07/compare-and-contrast-features-and.html" target="_blank">Compare and contrast the features and components of Java such as: platform independence, object orientation, encapsulation, etc.</a></li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<strong>Working With Java Data Types&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/declare-and-initialize-variables.html" target="_blank">Declare and initialize variables (including casting of primitive data types)</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/differentiate-between-object-reference.html" target="_blank">Differentiate between object reference variables and primitive variables</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/know-how-to-read-or-write-to-object.html" target="_blank">Know how to read or write to object fields</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/explain-objects-lifecycle-creation.html" target="_blank">Explain an Object's Lifecycle (creation, "dereference by reassignment" and garbage collection)</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/develop-code-that-uses-wrapper-classes.html" target="_blank">Develop code that uses wrapper classes such as Boolean, Double, and Integer. &nbsp;</a></li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<strong>Using Operators and Decision Constructs&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/02/use-java-operators-including.html" target="">Use Java operators; including parentheses to override operator precedence</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/test-equality-between-strings-and-other.html" target="_blank">Test equality between Strings and other objects using == and equals ()</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/create-if-and-ifelse-and-ternary.html" target="_blank">Create if and if/else and ternary constructs</a>&nbsp;</li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/use-switch-statement.html" target="_blank">Use a switch statement&nbsp;</a></li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<strong>Creating and Using Arrays&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/declare-instantiate-initialize-and-use.html" target="_blank">Declare, instantiate, initialize and use a one-dimensional array</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/declare-instantiate-initialize-and-use_12.html" target="_blank">Declare, instantiate, initialize and use multi-dimensional array</a></li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<strong>Using Loop Constructs&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/create-and-use-while-loops.html" target="_blank">Create and use while loops</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/create-and-use-for-loops-including.html" target="_blank">Create and use for loops including the enhanced for loop</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/create-and-use-dowhile-loops.html" target="_blank">Create and use do/while loops</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/07/compare-loop-constructs.html" target="_blank">Compare loop constructs</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/use-break-and-continue.html" target="_blank">Use break and continue</a> &nbsp;</li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<strong>Working with Methods and Encapsulation&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/create-methods-with-arguments-and.html" target="_blank">Create methods with arguments and return values; including overloaded methods</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/apply-static-keyword-to-methods-and.html" target="_blank">Apply the static keyword &nbsp;to methods and fields</a> &nbsp;</li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/create-and-overload-constructors.html" target="_blank">Create and overload constructors; including impact on default constructors</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/apply-access-modifiers.html" target="_blank">Apply access modifiers</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/apply-encapsulation-principles-to-class.html" target="_blank">Apply encapsulation principles to a class</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/determine-effect-upon-object-references.html" target="_blank">Determine the effect upon object references and primitive values when they are passed &nbsp;into methods that change the values</a></li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<a href="https://www.blogger.com/null" name="working-with-inheritance"></a>
<strong>Working with Inheritance&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/describe-inheritance-and-its-benefits.html" target="_blank">Describe inheritance and its benefits</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/develop-code-that-demonstrates-use-of.html" target="_blank">Develop code that demonstrates the use of polymorphism; including overriding and object type versus reference type</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/determine-when-casting-is-necessary.html" target="_blank">Determine when casting is necessary</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/use-super-and-this-to-access-objects.html" target="_blank">Use super and this to access objects and constructors</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/use-abstract-classes-and-interfaces.html" target="_blank">Use abstract classes and interfaces</a></li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<strong>Handling Exceptions&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/differentiate-among-checked-exceptions.html" target="_blank">Differentiate among checked exceptions, unchecked exceptions, and Errors</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/create-try-catch-block-and-determine.html" target="_blank">Create a try-catch block and determine how exceptions alter normal program flow</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/07/describe-advantages-of-exception.html" target="_blank">Describe the advantages of Exception handling</a>&nbsp;</li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/create-and-invoke-method-that-throws.html">Create and invoke a method that throws an exception</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/04/recognize-common-exception-classes-such.html" target="_blank">"Recognize common exception classes (such as NullPointerException, ArithmeticExcpetion, ArrayIndexOutOfBoundsException, ClassCastException)"</a></li>
</ul>
<div style="background-color: white; font-family: arial, helvetica, sans-serif; font-weight: bold;">
<h3>
<strong>Working with Selected classes from the Java API&nbsp;</strong></h3>
</div>
<ul style="background-color: white; font-family: arial, helvetica, sans-serif; list-style: none; margin-bottom: 10px; margin-left: 20px; padding: 0px 5px;">
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/manipulate-data-using-stringbuilder.html" target="_blank">Manipulate data using the StringBuilder class and its methods</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/creating-and-manipulating-strings.html" target="_blank">Creating and manipulating Strings</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/create-and-manipulate-calendar-data.html" target="_blank">Create and manipulate calendar data using classes from java.time.LocalDateTime, &nbsp;java.time.LocalDate, java.time.LocalTime, java.time.format.DateTimeFormatter, java.time.Period&nbsp;</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/declare-and-use-arraylist-of-given-type.html" target="_blank">Declare and use an ArrayList of a given type&nbsp;</a></li>
<li style="line-height: 20px; list-style-position: outside; margin-top: 2px;"><a href="http://xyzcode.blogspot.com/2016/03/write-simple-lambda-expression-that.html" target="_blank">Write a simple Lambda expression that consumes a Lambda Predicate expression</a></li>
</ul>
<div>
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;"><br /></span></span></div>
<div>
<span style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif;"><span style="line-height: 20px;"><a href="http://xyzcode.blogspot.com/2016/07/ocp-exam-1z0-809-breaks-down.html" target="_blank">Continue to OCPJP&gt;</a></span></span></div>
<div>
<h3>
</h3>
</div>



=====================
http://xyzcode.blogspot.com/2017/01/assessment-test-question-1.html

<script>

function setCookie(cname,cvalue,exdays) {
    cname = cname;
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function spentTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    var h0=getCookie('xyz-atqtimeh');
    var m0=getCookie('xyz-atqtimem');
    var s0=getCookie('xyz-atqtimes');

    var tm=getCookie('xyz-atqtimetm');
    if (h0 != "" && m0 != "" && s0 != "" && tm != "") {
       var time = (h - h0)*3600 + (m - m0)*60 + (s - s0);
       var minutes = Math.floor(time / 60);
       var seconds = time - minutes * 60;

       var ml = (tm - 1 - minutes);
       var sl = (60 - seconds);
       if (ml < 0) {
          document.getElementById('txt').innerHTML = "No time left";
       } else {
          document.getElementById('txt').innerHTML = ml + " minutes and " + sl + " seconds left";
       }
         
    } else {
       document.getElementById('txt').innerHTML = "You should start the test properly and answer all questions in one session.";
    }
}

function getCookie(cname) {
    cname = cname;
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

function showChoices(cname) {
    var answer=getCookie(cname);
    if (answer != "") {
       document.getElementById('chosen').innerHTML = "You have chosen: " + answer;
    } else {
       document.getElementById('chosen').innerHTML = "You didn't submit an answer.";
    }
}

function getChoices(cname) {
    var value = "";
    if (document.getElementById('A').checked) {
       value = value + "A,";
    }
    if(document.getElementById('B').checked) {
       value = value + "B,";
    }
    if(document.getElementById('C').checked) {
       value = value + "C,";
    }
    if(document.getElementById('D').checked) {
       value = value + "D,";
    }
    if(document.getElementById('E').checked) {
       value = value + "E,";
    }
    if(document.getElementById('F').checked) {
       value = value + "F,";
    }
    if(document.getElementById('G').checked) {
       value = value + "G,";
    }
    if(document.getElementById('H').checked) {
       value = value + "H,";
    }
    setCookie(cname, value, 30);
}
</script>

<a href="http://xyzcode.blogspot.com/2017/01/ocpjp-assessment-test.html">Question List</a><br />
<br />
<button onclick="spentTime()">Time Left</button>
<br />
<div id="txt">
</div>
<br />
Question:<br />
<br />
What is the result of executing the following application? (Choose all that apply.)<br />
<br />
<div class="code">
<div class="p1">
<div class="p2">
<span class="s2">&nbsp; 1 </span><span class="s1">import java.util.concurrent.*;</span></div>
<div class="p2">
<span class="s2">&nbsp; 2 </span><span class="s1">import java.util.stream.*;</span></div>
<div class="p2">
<span class="s2">&nbsp; 3 </span><span class="s1">public class test{</span></div>
<div class="p2">
<span class="s2">&nbsp; 4 </span><span class="s1">&nbsp; &nbsp; public static void await(CyclicBarrier cb) {</span></div>
<div class="p2">
<span class="s2">&nbsp; 5 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; try {</span></div>
<div class="p2">
<span class="s2">&nbsp; 6 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cb.await();</span></div>
<div class="p2">
<span class="s2">&nbsp; 7 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; } catch (InterruptedException | BrokenBarrierException e) {</span></div>
<div class="p2">
<span class="s2">&nbsp; 8 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //</span></div>
<div class="p2">
<span class="s2">&nbsp; 9 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div>
<div class="p2">
<span class="s2">&nbsp;10 </span><span class="s1">&nbsp; &nbsp; }</span></div>
<div class="p2">
<span class="s2">&nbsp;11 </span><span class="s1">&nbsp; &nbsp; public static void main(String...args) {</span></div>
<div class="p2">
<span class="s2">&nbsp;12 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; final CyclicBarrier cb = new CyclicBarrier(3, ()-&gt; System.out.printl</span><span class="s1">n("Pass!")); &nbsp;</span></div>
<div class="p2">
<span class="s2">&nbsp;13 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; ExecutorService service = Executors.newScheduledThreadPool(3);</span></div>
<div class="p2">
<span class="s2">&nbsp;14 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; IntStream.iterate(1, i-&gt;1)&nbsp;</span></div>
<div class="p2">
<span class="s2">&nbsp;15 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .limit(7)</span></div>
<div class="p2">
<span class="s2">&nbsp;16 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .forEach(i-&gt;service.submit(</span></div>
<div class="p2">
<span class="s2">&nbsp;17&nbsp;</span><span class="s1"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ()-&gt;await(cb))); &nbsp;</span></div>
<div class="p2">
<span class="s2">&nbsp;18 </span><span class="s1">&nbsp; &nbsp; &nbsp; &nbsp; service.shutdown();</span></div>
<div class="p2">
<span class="s2">&nbsp;19 </span><span class="s1">&nbsp; &nbsp; }&nbsp; &nbsp;</span></div>
<div class="p2">
<span class="s2">&nbsp;20 </span><span class="s1">} &nbsp;&nbsp;</span></div>
</div>
</div>
<br />
<div class="p2">
<br /></div>
<br />
Choice:<br />
<input id="A" type="checkbox" value="A" />A. It outputs Pass! once.<br />
<input id="B" type="checkbox" value="B" />B. It outputs Pass! twice.<br />
<input id="C" type="checkbox" value="C" />C. It outputs Pass! three times.<br />
<input id="D" type="checkbox" value="D" />D. The code will not compile because of line 7.<br />
<input id="E" type="checkbox" value="E" />E. The code will not compile because of line 13.<br />
<input id="F" type="checkbox" value="F" />F. The code will not compile because of line 15.<br />
<input id="G" type="checkbox" value="G" />G.&nbsp;<span class="s3">The code compiles but throws an exception at runtime.</span><span style="color: black; font-variant-ligatures: no-common-ligatures;">&nbsp;</span><br />
<input id="H" type="checkbox" value="H" />H. It compiles but waits forever at runtime.<br />
<br />
<button onclick="getChoices('xyz-atq1')">Submit</button>
<br />
<br />
<a href="http://xyzcode.blogspot.com/2017/01/assessment-test-question-2.html">Next Question</a><br />
<br />
<br />
<button onclick="document.getElementById('answernode').style.display='block'">Answer</button>
<button onclick="showChoices('xyz-atq1')">You answered</button>
<br />
<div id="chosen">
</div>
<br />
<br />
<div id="answernode" style="display: none;">
Answer: B, H<br />
<br />
Explain:&nbsp;<span class="s1">new CyclicBarrier(3, ()-&gt; System.out.printl</span><span class="s1">n("Pass!")); &nbsp;created aCyclicBarrier with limit of 3 and barrier action as printing "Pass!".</span><br />
<br />
IntStream.iterate(1, i-&gt;1) generates a stream of 1, .limit(7) gets the first 7 elements from the stream, .forEach()&nbsp;submits a new thread to ExecutorService for each one of the stream elements, for each thread, ()-&gt;await(cb) represents the task submitted, which calls CyclicBarrier's await() method. <br />
<br />
CyclicBarrier has a limit 3, the executor's thread pool has size 3, the total thread number submitted to ExecutorService is 7. The first 3 threads in thread pool calls await() 3 times, thus breaks the CyclicBarrier, gets "Pass!" printed once; the next 3 threads in thread pool calls await() 3 times, thus breaks the CyclicBarrier, gets "Pass!" printed twice; the 7th thread is submitted into the thread pool and calls await(), since the second and third await() has never been called, the barrier is never broken and the program hangs.<br />
<br />
service.shutdown(); does not actually stop any tasks that have already been submitted to the thread executor. Since your thread submitting is done through the stream forEach, even though the main thread exits firstly, all the 7 Callables are still submitted to the ExecutorService (3 in thread pool, the other 4 in ScheduledThreadPoolExecutor's workQueue).<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/WCynEMqo8OY/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/WCynEMqo8OY?feature=player_embedded" width="320"></iframe></div>
<br />
<br />
Study:</div>
<br />
<br />