What is the difference between context and init parameters in servlet configuration?
- Context parameters are set at the application level, while init parameters are at the servlet level.
- Context parameters are used for initialization, and init parameters are used for configuration.
- Init parameters are set at the application level, while context parameters are at the servlet level.
- Init parameters are used for initialization, and context parameters are used for configuration.
Context parameters are set at the application level and are shared among all servlets, while init parameters are specific to each servlet. Init parameters are configured in the servlet's declaration in the web.xml file.
How would a filter log request information without altering the request itself?
- Use a separate logging library
- Use a wrapper around the ServletResponse
- Use response.getWriter().write()
- Use response.log() method
To log request information without altering the response, a filter can use a wrapper around the ServletResponse. This allows capturing the response data without modifying it.
Which component in a Java EE application is responsible for managing connection pooling?
- Connection Pool
- Enterprise JavaBeans (EJB)
- JDBC Driver
- Servlet Container
Connection pooling is typically managed by a dedicated component known as the connection pool, which handles the creation, management, and recycling of database connections in a Java EE application.
When a connection is closed in a connection pool, what actually happens to that connection?
- It is immediately returned to the pool
- It is marked as unavailable
- It is permanently deleted
- It is physically closed
When a connection is closed in a connection pool, it is not physically closed but rather returned to the pool, making it available for reuse. This enhances efficiency by minimizing the need for new connections.
How does connection pooling improve the performance of database-driven applications?
- Caches database queries
- Has no impact on database connections
- Increases the number of open database connections
- Reduces the number of open database connections
Connection pooling improves performance by reducing the number of open database connections, reusing existing ones, and avoiding the overhead of opening and closing connections frequently.
What role does the JDBC API play in connection pooling?
- Deals with servlet lifecycle
- Handles SQL queries
- Manages database connections
- Provides database authentication
The JDBC API is responsible for managing database connections in connection pooling, ensuring efficient utilization and reuse of connections in a database-driven application.
How does a servlet container typically interact with a connection pool?
- It delegates management to the application.
- It directly manages the pool.
- It doesn't interact with connection pools.
- It relies on the database server for connection management.
In a typical scenario, a servlet container directly manages the connection pool, ensuring efficient utilization and management of database connections within the application.
What is the impact of setting a very high or very low size for the connection pool?
- Both high and low sizes have a negative impact on performance.
- High size can lead to resource wastage, while low size may cause performance issues.
- High size improves performance, but low size reduces resource usage.
- Setting size doesn't affect performance.
Setting a very high size for the connection pool can lead to resource wastage, while a very low size may cause performance issues. It's essential to find an optimal size to balance performance and resource usage effectively.
How can stale or broken database connections in the pool be handled effectively?
- By ignoring them and letting the database manage it.
- By logging the issue and continuing to use the connection.
- By notifying the database administrator.
- By removing them from the pool and establishing new connections.
Stale or broken database connections in the pool can be handled effectively by removing them from the pool and establishing new connections. This helps maintain a reliable and efficient connection pool for the servlet container.
In connection pooling, the pool size is defined by the _________ and _________ parameters.
- initialConnections, maxConnections
- initialSize, maxSize
- minConnections, maxConnections
- minSize, maxSize
In connection pooling, the pool size is defined by the initialSize and maxSize parameters.