<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sonali Gupta</title>
    <description>The latest articles on DEV Community by Sonali Gupta (@sonali_g_).</description>
    <link>https://dev.to/sonali_g_</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F314368%2F10aec47a-86b4-4fe1-a61c-13092ed1eb60.jpg</url>
      <title>DEV Community: Sonali Gupta</title>
      <link>https://dev.to/sonali_g_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sonali_g_"/>
    <language>en</language>
    <item>
      <title>ExecutorService in Java</title>
      <dc:creator>Sonali Gupta</dc:creator>
      <pubDate>Tue, 14 Jul 2020 18:50:29 +0000</pubDate>
      <link>https://dev.to/sonali_g_/executorservice-in-java-40bd</link>
      <guid>https://dev.to/sonali_g_/executorservice-in-java-40bd</guid>
      <description>&lt;p&gt;ExecutorService ( Java's thread pool framework) -&lt;/p&gt;

&lt;p&gt;In java, its always being easy to run a method or a piece of code asynchronously. &lt;/p&gt;

&lt;p&gt;For Example - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjqlwzh0k1yudr857su70.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjqlwzh0k1yudr857su70.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In java, thread can be created in two ways,&lt;br&gt;
1) By extending Thread class&lt;br&gt;
2) By implementing Runnable Interface&lt;/p&gt;

&lt;p&gt;If we want to execute a task asynchronously, than we can create a new instance of thread and assign the task to it. And start the thread, it will execute asynchronously.&lt;/p&gt;

&lt;p&gt;Task can be executed asynchronously using threads. But, if suppose we want to execute 100000 tasks than we have to create 100000 threads. And each thread can execute one task at a time asynchronously. But, creating 100000 threads for each task is not the feasibile solution.&lt;/p&gt;

&lt;p&gt;The Java ExecutorService is the interface which allows us to execute tasks on threads asynchronously. The Java ExecutorService interface is present in the java.util.concurrent package. The ExecutorService helps in maintaining a pool of threads and assigns them tasks. It also provides the facility to queue up tasks until there is a free thread available if the number of tasks is more than the threads available.&lt;/p&gt;

&lt;p&gt;By using Executor service, we can create the pool of threads.&lt;/p&gt;

&lt;p&gt;ExecutorService executorService = Executors.newFixedThreadPool(10);&lt;/p&gt;

&lt;p&gt;Here, we are creating a pool of 10 threads. And 100000 tasks are submitted to the executor service. Internally, it assigns each task to the threads present in the thread pool. Max 10 threads can execute the task at a time. And the tasks are stored in the blocking queue.&lt;/p&gt;

&lt;p&gt;Why Blocking Queue ? - Because No two threads can access the queue at the same time.&lt;/p&gt;

&lt;p&gt;Once the threads execution completes, it fetches the next task from the blocking queue. And subsequently, all the threads present in the thread pool do the same.&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Looping over array in JavaScript</title>
      <dc:creator>Sonali Gupta</dc:creator>
      <pubDate>Wed, 12 Feb 2020 19:45:30 +0000</pubDate>
      <link>https://dev.to/sonali_g_/looping-over-array-in-javascript-27oa</link>
      <guid>https://dev.to/sonali_g_/looping-over-array-in-javascript-27oa</guid>
      <description>&lt;p&gt;Looping over arrays-&lt;br&gt;
There’s a few methods for looping over arrays in Javascript. We’ll start with the classical ones and move towards additions made to the standard.&lt;/p&gt;

&lt;p&gt;While -&lt;br&gt;
let index = 0;&lt;br&gt;
const array = [1,2,3,4,5,6];&lt;/p&gt;

&lt;p&gt;while (index &amp;lt; array.length) {&lt;br&gt;
  console.log(array[index]);&lt;br&gt;
  index++;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;for (classical)-&lt;br&gt;
const array = [1,2,3,4,5,6];&lt;br&gt;
for (let index = 0; index &amp;lt; array.length; index++) {&lt;br&gt;
  console.log(array[index]);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;forEach-&lt;br&gt;
const array = [1,2,3,4,5,6];&lt;/p&gt;

&lt;p&gt;array.forEach(function(current_value, index, array) {&lt;br&gt;
  console.log(&lt;code&gt;At index ${index} in array ${array} the value is ${current_value}&lt;/code&gt;);&lt;br&gt;
});&lt;br&gt;
// =&amp;gt; undefined&lt;/p&gt;

&lt;p&gt;map-&lt;br&gt;
The last construct was useful, however, it doesn’t return a new array which might be undesirable for your specific case. map solves this by applying a function over every element and then returning the new array.&lt;/p&gt;

&lt;p&gt;const array = [1,2,3,4,5,6];&lt;br&gt;
const square = x =&amp;gt; Math.pow(x, 2);&lt;br&gt;
const squares = array.map(square);&lt;br&gt;
console.log(&lt;code&gt;Original array: ${array}&lt;/code&gt;);&lt;br&gt;
console.log(&lt;code&gt;Squared array: ${squares}&lt;/code&gt;);&lt;br&gt;
The full signature for map is .map(current_value, index, array).&lt;/p&gt;

&lt;p&gt;reduce-&lt;br&gt;
The reduce() method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.&lt;/p&gt;

&lt;p&gt;const array = [1,2,3,4,5,6];&lt;br&gt;
const sum = (x, y) =&amp;gt; x + y;&lt;br&gt;
const array_sum = array.reduce(sum, 0);&lt;br&gt;
console.log(&lt;code&gt;The sum of array: ${array} is ${array_sum}&lt;/code&gt;);&lt;/p&gt;

&lt;p&gt;filter-&lt;br&gt;
Filters elements on an array based on a boolean function.&lt;/p&gt;

&lt;p&gt;const array = [1,2,3,4,5,6];&lt;br&gt;
const even = x =&amp;gt; x % 2 === 0;&lt;br&gt;
const even_array = array.filter(even);&lt;br&gt;
console.log(&lt;code&gt;Even numbers in array ${array}: ${even_array}&lt;/code&gt;);&lt;/p&gt;

&lt;p&gt;every-&lt;br&gt;
Got an array and want to test if a given condition is met in every element?&lt;/p&gt;

&lt;p&gt;const array = [1,2,3,4,5,6];&lt;br&gt;
const under_seven = x =&amp;gt; x &amp;lt; 7;&lt;/p&gt;

&lt;p&gt;if (array.every(under_seven)) {&lt;br&gt;
  console.log('Every element in the array is less than 7');&lt;br&gt;
} else {&lt;br&gt;
  console.log('At least one element in the array was bigger than 7');&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;some-&lt;br&gt;
Test if at least one element matches our boolean function.&lt;/p&gt;

&lt;p&gt;const array = [1,2,3,9,5,6,4];&lt;br&gt;
const over_seven = x =&amp;gt; x &amp;gt; 7;&lt;/p&gt;

&lt;p&gt;if (array.some(over_seven)) {&lt;br&gt;
  console.log('At least one element bigger than 7 was found');&lt;br&gt;
} else {&lt;br&gt;
  console.log('No element bigger than 7 was found');&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Java Multithreading &amp; Concurrency Overview</title>
      <dc:creator>Sonali Gupta</dc:creator>
      <pubDate>Tue, 28 Jan 2020 18:36:02 +0000</pubDate>
      <link>https://dev.to/sonali_g_/java-multithreading-concurrency-overview-59eb</link>
      <guid>https://dev.to/sonali_g_/java-multithreading-concurrency-overview-59eb</guid>
      <description>&lt;p&gt;Multithreading and Concurrency in Java-&lt;br&gt;
 Java was one of the first languages to make multithreading easily available to developers. Java had multithreading capabilities from the very beginning. Therefore, Java developers often face the problems described above. That is the reason I am writing this trail on Java concurrency. As notes to myself, and any fellow Java developer whom may benefit from it.&lt;/p&gt;

&lt;p&gt;The trail will primarily be concerned with multithreading in Java, but some of the problems occurring in multithreading are similar to problems occurring in multitasking and in distributed systems. References to multitasking and distributed systems may therefore occur in this trail too. Hence the word "concurrency" rather than "multithreading".&lt;/p&gt;

&lt;p&gt;Concurrency Models-&lt;/p&gt;

&lt;p&gt;The first Java concurrency model assumed that multiple threads executing within the same application would also share objects. This type of concurrency model is typically referred to as a "shared state concurrency model". A lot of the concurrency language constructs and utilities are designed to support this concurrency model.&lt;/p&gt;

&lt;p&gt;However, a lot has happened in the world of concurrent architecture and design since the first Java concurrency books were written, and even since the Java 5 concurrency utilities were released&lt;/p&gt;

&lt;p&gt;The shared state concurrency model causes a lot of concurrency problems which can be hard to solve elegantly. Therefore, an alternative concurrency model referred to as "shared nothing" or "separate state" has gained popularity. In the separate state concurrency model the threads do not share any objects or data. This avoids a lot of the concurrent access problems of the shared state concurrency model.&lt;/p&gt;

&lt;p&gt;New, asynchronous "separate state" platforms and toolkits like Netty, Vert.x and Play / Akka and Qbit have emerged. New non-blocking concurrency algorithms have been published, and new non-blocking tools like the LMax Disrupter have been added to our toolkits. New functional programming parallelism has been introduced with the Fork and Join framework in Java 7, and the collection streams API in Java 8.&lt;/p&gt;

</description>
      <category>java</category>
      <category>tutorial</category>
      <category>multithreading</category>
      <category>concurrency</category>
    </item>
    <item>
      <title>Java Memory Model</title>
      <dc:creator>Sonali Gupta</dc:creator>
      <pubDate>Sat, 11 Jan 2020 19:50:34 +0000</pubDate>
      <link>https://dev.to/sonali_g_/java-memory-model-1oo7</link>
      <guid>https://dev.to/sonali_g_/java-memory-model-1oo7</guid>
      <description>&lt;p&gt;Hi Everyone,&lt;/p&gt;

&lt;p&gt;Understanding JVM Memory Model, Java Memory Management are very important if you want to understand the working of Java Garbage Collection. Today we will look into memory management in Java, different parts of JVM memory.&lt;/p&gt;

&lt;p&gt;JVM memory is divided into separate parts. At broad level, JVM Heap memory is physically divided into two parts – Young Generation and Old Generation.&lt;/p&gt;

&lt;p&gt;Memory Management in Java – &lt;/p&gt;

&lt;p&gt;Young Generation-&lt;br&gt;
The young generation is the place where all the new objects are created. When the young generation is filled, garbage collection is performed. This garbage collection is called Minor GC. Young Generation is divided into three parts – Eden Memory and two Survivor Memory spaces.&lt;/p&gt;

&lt;p&gt;Important Points about Young Generation Spaces:&lt;/p&gt;

&lt;p&gt;Most of the newly created objects are located in the Eden memory space.&lt;br&gt;
When Eden space is filled with objects, Minor GC is performed and all the survivor objects are moved to one of the survivor spaces.&lt;br&gt;
Minor GC also checks the survivor objects and move them to the other survivor space. So at a time, one of the survivor space is always empty.&lt;br&gt;
Objects that are survived after many cycles of GC, are moved to the Old generation memory space. Usually, it’s done by setting a threshold for the age of the young generation objects before they become eligible to promote to Old generation.&lt;/p&gt;

&lt;p&gt;Old Generation -&lt;br&gt;
Old Generation memory contains the objects that are long-lived and survived after many rounds of Minor GC. Usually, garbage collection is performed in Old Generation memory when it’s full. Old Generation Garbage Collection is called Major GC and usually takes a longer time.&lt;/p&gt;

&lt;p&gt;Stop the World Event -&lt;br&gt;
All the Garbage Collections are “Stop the World” events because all application threads are stopped until the operation completes.&lt;/p&gt;

&lt;p&gt;Since Young generation keeps short-lived objects, Minor GC is very fast and the application doesn’t get affected by this.&lt;/p&gt;

&lt;p&gt;However, Major GC takes a long time because it checks all the live objects. Major GC should be minimized because it will make your application unresponsive for the garbage collection duration. So if you have a responsive application and there are a lot of Major Garbage Collection happening, you will notice timeout errors.&lt;/p&gt;

&lt;p&gt;The duration taken by garbage collector depends on the strategy used for garbage collection. That’s why it’s necessary to monitor and tune the garbage collector to avoid timeouts in the highly responsive applications.&lt;/p&gt;

&lt;p&gt;Permanent Generation -&lt;br&gt;
Permanent Generation or “Perm Gen” contains the application metadata required by the JVM to describe the classes and methods used in the application. Note that Perm Gen is not part of Java Heap memory.&lt;/p&gt;

&lt;p&gt;Perm Gen is populated by JVM at runtime based on the classes used by the application. Perm Gen also contains Java SE library classes and methods. Perm Gen objects are garbage collected in a full garbage collection.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
  </channel>
</rss>
