Server Side Programming Articles - Page 1579 of 2650

Difference between Fixed thread pool and cached thread pool.

Himanshu shriv
Updated on 09-Sep-2020 09:41:08

4K+ Views

Executor framework are designed using thread pool concept. Thread pool is the way to reuse the already created thread instead of creating a new thread every time to execute the current task.Executors class provides a factory method to create thread pools. The ThreadPoolExecutor class is the base implementation for the executors that are returned from many of the Executors  factory methods.Sr. No.KeyFixed Thread PoolCached Thread Pool1BasicAs per Java Doc −Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most nThreads threads will be active processing tasks. If additional ... Read More

Difference between Executor and ExecutorServices in Java

Himanshu shriv
Updated on 09-Sep-2020 09:36:46

2K+ Views

Executor and ExecutorServices both interfaces are part of the Executor framework. It is released with Java 5. In java, thread creation is very expensive operation so we should  reuse the available thread instead of starting a new thread every time and we can achieve the same using Executor framework.Executor framework use the thread pool to execute the task parallel which helps to optimize response time and resource utilization. It provides four types of built in thread pools −Fixed Thread PoolCached Thread PoolScheduled Thread PoolSingle Thread ExecutorSr. No.KeyExecutorExecutorServices1BasicIt is a parent interfaceIt extends Executor Interface2MethodIt has execute() methodIt has submit() method3Return TypeIt ... Read More

Difference between Runnable and Callable interface in java

Himanshu shriv
Updated on 09-Sep-2020 09:33:21

7K+ Views

Runnable and Callable both functional interface. Classes which are implementing these interfaces are designed to be executed by another thread.Thread can be started with Ruunable and they are two ways to start a new thread: one is by subclassing Thread class and another is implementing Runnable interface.Thread class does not have constructor for callable so we should use ExecutorService  class for executing thread.Sr. No.KeyRunnableCallable1PackageIt belongs to Java.langIt belongs to java.util.concurrent2Thread CreationWe can create thread by passing runnable as a parameter.We can’t create thread by passing callable as parameter  3Return TypeRuunable does not return anythingCallable can return results4.MethodIt has run() methodIt ... Read More

Difference between Streams and Collections in Java 8

Himanshu shriv
Updated on 09-Sep-2020 09:31:05

6K+ Views

Java Collections framework is used for storing and manipulating group of data. It is an in-memory data structure and every element in the collection should be computed before it can be added in the collections.Stream API is only used for processing group of data. It does not modify the actual collection, they only provide the result as per the pipelined methods.Sr. No.KeyCollectionsStreams1BasicIt is used for storing and manipulating group of dataStream API is only used for processing group of data2PackageAll the classes and interfaces of this API is in the Java.util packageAll the classes and interfaces of this API is ... Read More

How to create bars with gap among them if there are more categories using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:38:50

152 Views

When the number of categories is large in numbers for a variable and we want to create a bar plot then the display of the bar plot becomes a little ambiguous because the bars are plotted very close to each other. To make the bars clearly visible, we can reduce the width of the bars and set different colors for them to make them visually attractive.geom_bar(width=0.2,color="red")Consider the below data frame −x

How to save the summary statistics into a data frame in R?

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:32:19

5K+ Views

When we find the summary statistics of a data frame then the output is returned as a table and each of the column records the minimum, first quartile, median, median, third quartile, and maximum with their names. If we want to save this summary as a data frame then it is better to calculate it with apply function and store it as data.frame.ExampleConsider the below data frame − Live Demox1

How to determine the row that have min and max values in an R data frame column?

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:22:05

2K+ Views

In data analysis, often we require to determine the minimum and maximum values because these values help us to understand the limits of a column or variable under consideration. This can be done by using which.max for maximum and which.min for minimum with single square brackets to extract the rows.ExampleConsider the below data frame − Live Demox1

How to reduce the space between two plots that are joined with grid.arrange in R?

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:14:01

2K+ Views

When we join or combine plots using grid.arrange the scales of the first plot comes in between as X-axis even if the independent variable in both of the plots is same.Therefore, we might want to remove the space between the plots while joining to get only one X-axis. This can be done by using theme function.ExampleConsider the below data frame − Live Demoset.seed(123) x

How to create gridlines that matches with Y-axis values in the plot created by using plot function in R?

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:09:05

375 Views

When we create a plot in R and draw gridlines then the gridlines are drawn on the basis of the values provided inside the grid function, therefore, it may or may not match with the Y-axis labels. But it can be done, we just need to set the values inside the grid function to NULL.ExampleConsider the below plot − Live Demox

How to create a column with binary variable based on a condition of other variable in an R data frame?

Nizamuddin Siddiqui
Updated on 09-Sep-2020 08:00:43

9K+ Views

Sometimes we need to create extra variable to add more information about the present data because it adds value. This is especially used while we do feature engineering. If we come to know about something that may affect our response then we prefer to use it as a variable in our data, hence we make up that with the data we have. For example, creating another variable applying conditions on other variable such as creating a binary variable for goodness if the frequency matches a certain criterion.ExampleConsider the below data frame − Live Demoset.seed(100) Group

Advertisements