Found 33676 Articles for Programming

Difference between scheduledThread pool and Single Thread Executor.

Himanshu shriv
Updated on 09-Sep-2020 11:16:53

1K+ Views

Sr. No.KeyScheduled Thread PoolSingle Thread Executor1BasicCreates a thread pool that can schedule commands to run after a given delay, or to execute periodically. Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time2QueueIt uses Delay Queue to store tasks. Schedule the task based on time delay.It uses blocking queue.3Thread LifetimeT he number of threads to keep in the pool, even if they are idleRecreate thread if killed because of the task.4.Thread Pool SizeIt always has a single thread running.The thread pool can grow from zero threads to Integer.MAX_VALUE5.Use CaseWe should used fixedthreadpool, ... Read More

Program to find compound interest in C++

Ayush Gupta
Updated on 09-Sep-2020 11:17:09

419 Views

In this tutorial, we will be discussing a program to find compound interest.Compound interest is the interest by adding the current interest to the principal sum and then calculating the interest on the updated amount.Example Live Demo#include using namespace std; int main(){    double principle = 10000, rate = 10.25, time = 5;    //calculating compound interest    double CI = principle * (pow((1 + rate / 100), time));    cout

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

5K+ 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

Difference between JDK dynamic proxy and CGLib proxy in Spring

Himanshu shriv
Updated on 09-Sep-2020 09:28:58

3K+ Views

Spring AOP is proxy based. Spring used two types of proxy strategy one is JDK dynamic proxy and other one is CGLIB proxy.JDK dynamic proxy is available with the JDK. It can be only proxy by interface so target class needs to implement interface. In your is implementing one or more interface then spring will automatically use JDK dynamic proxies.On the other hand, CGLIB is a third party library which spring used for creating proxy. It can create proxy by subclassing. Spring uses CGLIB for proxy if class is not implementing interface.Sr. No.KeyJDK dynamic proxyCGLIB proxy1BasicIt can be only proxy ... Read More

Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

Himanshu shriv
Updated on 09-Sep-2020 09:26:49

2K+ Views

Applicationcontext.xml - It is standard spring context file which contains all beans and the configuration  that are common among all the servlets. It is optional file in case of web app. Spring uses ContextLoaderListener to load this file in case of web application. Spring-servlet.xml- It is a single entry point for Spring. DispatcherServlet scan this file and starts to load its component. It defines the bean and configuration that are only related to that servlet.In Spring MVC application we chain them in below order −          web.xml --> dispatcher servlet --> application contextSr. No.KeyApplicationContext.xmlSpring-servlet.xml1BasicapplicationContext.xml  defines the beans that ... Read More

Difference between DispatcherServlet and ContextLoaderListener in Spring

Himanshu shriv
Updated on 09-Sep-2020 09:06:17

2K+ Views

ContextLoaderListener creates a root web-application-context for the web-application and puts it in the ServletContext. This context can be used to load and unload the spring-managed beans ir-respective of what technology is being used in the controller layer(Struts or Spring MVC).DispatcherServlet creates its own WebApplicationContext and the handlers/controllers/view-resolvers are managed by this context.Sr. No.KeyDispatcherServletContextLoaderListener1BasicThe task of the DispatcherServlet  is to send request to the specific Spring MVC controller ContextLoaderListener  reads the Spring configuration file (with value given against contextConfigLocation in web.xml ), parses it and loads the singleton bean defined in that config file. So we initialize the web application with ContextLoaderListener ... Read More

Difference between @Inject and @Autowired

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

9K+ Views

@Inject and @Autowired both annotations are used for autowiring in your application.@Inject annotation is part of Java CDI which was introduced in Java 6, whereas @Autowire annotation is part of spring framework. Both annotations fulfill same purpose therefore, anything of these we can use in our application.Sr. No.Key@Inject@Autowired1BasicIt is part of Java CDIIt is part of Spring framework2RequiredIt has no required attributeIt has required attribute3Default ScopeDefault scope of the autowired beans is SingletonDefault scope of the inject beans is prototype4AmbiguityIn case of ambiguity in beans for injection then @Named qualifier should be added in your code.In case of ambiguity in ... Read More

Advertisements