Programming Articles - Page 1563 of 3363

How to run multiple async tasks and waiting for them all to complete in C#?

Nizamuddin Siddiqui
Updated on 05-Dec-2020 06:33:01

3K+ Views

The Task.WaitAll blocks the current thread until all other tasks have completed execution.The Task.WhenAll method is used to create a task that will complete if and only if all the other tasks have complete. In the 1st example, we could see that when using Task.WhenAll the task complete is executed before the other tasks are completed. This means that Task.WhenAll doesn’t block the execution. And in the 2nd example, we could see that when using Task.WaitAll the task complete is executed only after all the other tasks are completed. This means that Task.WaitAll block the execution.Examplestatic void Main(string[] args){   ... Read More

What is the difference between All and Any in C# Linq?

Nizamuddin Siddiqui
Updated on 05-Dec-2020 06:30:58

2K+ Views

Any() method returns true if at least one of the elements in the source sequence matches the provided predicate. Otherwise, it returns false. On the other hand, the All() method returns true if every element in the source sequence matches the provided predicate. Otherwise, it returns falseExamplestatic void Main(string[] args){    IEnumerable doubles = new List { 1.2, 1.7, 2.5, 2.4 };    bool result = doubles.Any(val => val < 1);    System.Console.WriteLine(result);    IEnumerable doubles1 = new List { 0.8, 1.7, 2.5, 2.4 };    bool result1 = doubles1.Any(val => val < 1);    System.Console.WriteLine(result1);    Console.ReadLine(); }OutputFalse TrueExamplestatic ... Read More

What is dependency inversion principle and how to implement in C#?

Nizamuddin Siddiqui
Updated on 05-Dec-2020 06:29:13

838 Views

High-level modules should not depend on low-level modules. Both should depend on abstractions.Abstractions should not depend on details. Details should depend on abstractions.This principle is primarily concerned with reducing dependencies among the code modules.ExampleCode Before Dependency Inversionusing System; namespace SolidPrinciples.Dependency.Invertion.Before{    public class Email{       public string ToAddress { get; set; }       public string Subject { get; set; }       public string Content { get; set; }       public void SendEmail(){          //Send email       }    }    public class SMS{       public ... Read More

How to display open cursors in Oracle?

Kiran P
Updated on 05-Dec-2020 07:18:26

7K+ Views

Problem:You want to display open cursors in Oracle.SolutionWe can query the data dictionary to determine the number of cursors that are open per session. "V$SESSION" provides a more accurate number of the cursors currently open than "V$OPEN_CURSOR".Exampleselect  a.value  , c.username  , c.machine  , c.sid  , c.serial# from v$sesstat a  , v$statname b  , v$session c where a.statistic# = b.statistic# and c.sid  = a.sid and b.name  = 'opened cursors current' and a.value  != 0 and c.username IS NOT NULL order by 1, 2;The OPEN_CURSORS initialization parameter determines the maximum number of cursors a session can have open.Read More

How to identify the SQL consuming more resources in Oracle?

Kiran P
Updated on 05-Dec-2020 06:30:12

2K+ Views

Problem:You want to identify the SQL statements consuming more resources in Oracle.Solution“V$SQLSTATS" view displays performance statistics for SQL statements that have recently executed. You can also use "V$SQL” and “V$SQLAREA" to report on SQL resource usage. "V$SQLSTATS” is faster and retains information for a longer period of time, but contains only a subset of the columns in “V$SQL" and "V$SQLAREA”.Exampleselect * from( select   sql_text  ,buffer_gets  ,disk_reads  ,sorts  ,cpu_time/1000000 cpu_sec  ,executions  ,rows_processed from v$sqlstats order by cpu_time DESC) where rownum < 20;

How to display a SQL execution progress along with execution plan in Oracle?

Kiran P
Updated on 05-Dec-2020 06:23:46

3K+ Views

Problem:You want to view where Oracle SQL is taking time within a SQL execution plan.SolutionWith Oracle 11g version, we can view SQL execution plan progress while the SQL is running. The “V$SQL_PLAN_MONITOR” view contains a row for each step of a SQL statement’s execution plan. Below SQL will help to view the execution plan along with the progress.The “V$SQL_PLAN_MONITOR" provides you with information on the steps that are using the most resources. The statistics in "V$SQL_PLAN_MONITOR” are updated every second.We can also generate a real time text, HTML, or even a XML report of query progress within an execution plan ... Read More

How to determine the approximate amount of SQL work left in Oracle?

Kiran P
Updated on 05-Dec-2020 06:22:48

1K+ Views

Problem:You want to know how much longer a long running SQL might ake to finish.SolutionWe can use “V$SESSION_LONGOPS" view to know the approximate time of a query left to execute. "V$SESSION_LONGOPS” view displays the status of various database operations that have been running for longer than six seconds. Please note that this view give you only a rough estimate of when a SQL might complete.Exampleselect   a.username  , a.opname  , b.sql_text  , to_char(a.start_time, 'DD-MON-YY HH24:MI') start_time  , a.elapsed_seconds how_long  , a.time_remaining secs_left  , a.sofar  , a.totalwork  , round(a.sofar/a.totalwork*100, 2) percent from v$session_longops a     ,v$sql         ... Read More

How to monitor real time SQL execution statistics in Oracle?

Kiran P
Updated on 05-Dec-2020 06:22:04

3K+ Views

Problem:You want to monitor currently executing SQL statistics in Oracle.SolutionIf your database is Oracle Database 11g, you can use the following query to select from the “V$SQL_MONITOR” to monitor the near real time resource consumption of SQL queries.The statistics in “V$SQL_MONITOR” are updated every second. This helps us to view the resource consumption as it updates. These statistics are gathered by default when a SQL statement runs in parallel or consumes more than 5 seconds of CPU or I/O time.The “V$SQL_MONITOR" view includes a subset of statistics contained in the "V$SQL”, “V$SQLAREA", and "V$SQLSTATS” views.The “V$SQL_MONITOR" view displays real-time statistics ... Read More

How to limit Database Resources per Session in Oracle?

Kiran P
Updated on 05-Dec-2020 06:21:10

3K+ Views

Problem:You want to limit the amount of resources a user can consume in your database.SolutionTo limit the resources, we can follow below steps.We can use below SQL statement to view the current setting of RESOURCE_LIMIT in our database.select name, value from v$parameter where name='resource_limit';Create a profile to limit the resources and assign it to a user. It won’t limit the CPU utilization though.ExampleCREATE PROFILE test_profile LIMIT    SESSIONS_PER_USER          2    CPU_PER_SESSION            UNLIMITED    CPU_PER_CALL               300000    CONNECT_TIME           ... Read More

How to use Primary Key Constraints and Foreign Key Constraints to enforce database integrity in Oracle?

Kiran P
Updated on 05-Dec-2020 06:20:06

600 Views

Problem:You want to use Primary Key Constraints and Foreign Key Constraints to enforce database integrity in Oracle.SolutionAny DML statement (an INSERT, UPDATE, or DELETE) executed on tables defined with integrity, helps to ensures that the rows in the tables maintain their integrity.Let’s look at some examples that show the enforcement of a primary key constraint. The customers table’s primary key is the customer_id column, which means that every value stored in the customer_id column must be unique. If you try to insert a row with a duplicate value for a primary key, the database returns the error ORA-00001, as in ... Read More

Advertisements